Learn R Programming

stenR (version 0.6.9)

export_ScoringTable: Export ScoringTable

Description

After creation of ScoringTable it can be handy to export it into universally recognized and readable format. Two formats are currently supported: csv and json. They can be imported back into ScoringTable using import_ScoringTable() function.

  • csv format is universally readable - it can be opened, edited and altered (eg. before publication) in any spreadsheet editor. In case of ScoringTable created from GroupedScoreTable, GroupConditions can be exported to another csv file, creating two different files.

  • json format can be more obtuse, but it allows export of both ScoringTable itself and GroupConditions in the same json file.

Usage

export_ScoringTable(
  table,
  out_file,
  method = c("csv", "json", "object"),
  cond_file
)

Value

list containing ScoringTable as a tibble and GroupConditions

if method = "object". NULL for other methods

Arguments

table

A ScoringTable object to export

out_file

Output file. Ignored if method = "object"

method

Method for export, either "csv", "json" or "object"

cond_file

Output file for GroupConditions. Used only if method = csv and table created with GroupedScoreTable.

See Also

import_ScoringTable

Other import/export functions: export_ScaleSpec(), import_ScaleSpec(), import_ScoringTable()

Examples

Run this code
# Scoring table to export / import #

Consc_ST <- 
  GroupedFrequencyTable(
    data = IPIP_NEO_300,
    conditions = GroupConditions("Sex", "M" ~ sex == "M", "F" ~ sex == "F"), 
    var = "C") |>
  GroupedScoreTable(scale = STEN) |>
  to_ScoringTable(min_raw = 60, max_raw = 300)

#### Export/import method: csv ####

scoretable_csv <- tempfile(fileext = ".csv")
conditions_csv <- tempfile(fileext = ".csv")

export_ScoringTable(
  table = Consc_ST,
  out_file = scoretable_csv,
  method = "csv",
  cond_file = conditions_csv
)

## check if these are regular csv files
writeLines(head(readLines(scoretable_csv)))
writeLines(head(readLines(conditions_csv)))

imported_from_csv <- import_ScoringTable(
  source = scoretable_csv,
  method = "csv",
  cond_file = conditions_csv
)

all.equal(Consc_ST, imported_from_csv)

#### Export/import method: json ####
scoretable_json <- tempfile(fileext = ".json")

export_ScoringTable(
  table = Consc_ST,
  out_file = scoretable_json,
  method = "json"
)

## check if this is regular json file
writeLines(head(readLines(scoretable_json)))

imported_from_json <- import_ScoringTable(
  source = scoretable_json,
  method = "json"
)

all.equal(Consc_ST, imported_from_json)

Run the code above in your browser using DataLab