import_ScoringTable {stenR}R Documentation

Import ScoringTable

Description

ScoringTable can be imported from csv, json file or tibble. Source file or object can be either an output of export_ScoringTable() function, or created by hand - though it needs to be created following the correct format.

Usage

import_ScoringTable(
  source,
  method = c("csv", "json", "object"),
  cond_file,
  conditions
)

Arguments

source

Path to the file to import the ScoringTable from (for csv and json methods) or ScoringTable in form of data.frame (for object method)

method

Method for import, either csv, json or object

cond_file

File to import the GroupConditions from, if using csv method

conditions

GroupCondition object or list of up to two of them. Mandatory for object method and csv method if no cond_file is provided. If provided while using json method, original GroupConditions will be ignored.

Value

ScoringTable object

See Also

export_ScoringTable

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

Examples

# 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)

[Package stenR version 0.6.9 Index]