Read external csv data set definitions

defRead(filen, id = "id")

Arguments

filen

String file name, including full path. Must be a csv file.

id

string that includes name of id field. Defaults to "id"

Value

A data.table with data set definitions

See also

[distributions]

Examples

# Create temporary external "csv" file

test1 <- c(
  "varname,formula,variance,dist,link",
  "nr,7, 0,nonrandom,identity",
  "x1,.4, 0,binary,identity",
  "y1,nr + x1 * 2,8,normal,identity",
  "y2,nr - 0.2 * x1,0,poisson, log"
)

tfcsv <- tempfile()
writeLines(test1, tfcsv)

# Read external csv file stored in file "tfcsv"

defs <- defRead(tfcsv, id = "myID")
defs
#>    varname       formula variance      dist     link
#>     <char>        <char>    <int>    <char>   <char>
#> 1:      nr             7        0 nonrandom identity
#> 2:      x1            .4        0    binary identity
#> 3:      y1   nr + x1 * 2        8    normal identity
#> 4:      y2 nr - 0.2 * x1        0   poisson      log

unlink(tfcsv)

# Generate data based on external definition

genData(5, defs)
#> Key: <myID>
#>     myID    nr    x1        y1    y2
#>    <int> <num> <int>     <num> <int>
#> 1:     1     7     0  5.959429     7
#> 2:     2     7     0 12.481746     9
#> 3:     3     7     0  8.954772     7
#> 4:     4     7     1  8.650740     5
#> 5:     5     7     0  6.317463     7