Read external csv data set definitions for adding columns

defReadAdd(filen)

Arguments

filen

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

Value

A data.table with data set definitions

See also

[distributions]

Examples

# Create temporary external "csv" files

test1 <- c(
  "varname,formula,variance,dist,link",
  "nr,7, 0,nonrandom,identity"
)

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

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

tfcsv2 <- tempfile()
writeLines(test2, tfcsv2)

# Generate data based on external definitions

defs <- defRead(tfcsv1)
dt <- genData(5, defs)
dt
#> Key: <id>
#>       id    nr
#>    <int> <num>
#> 1:     1     7
#> 2:     2     7
#> 3:     3     7
#> 4:     4     7
#> 5:     5     7

# Add additional data based on external definitions

defs2 <- defReadAdd(tfcsv2)
dt <- addColumns(defs2, dt)
dt
#> Key: <id>
#>       id    nr    x1       y1    y2
#>    <int> <num> <int>    <num> <int>
#> 1:     1     7     0 4.821535     5
#> 2:     2     7     0 7.461437     8
#> 3:     3     7     0 2.851221     7
#> 4:     4     7     0 7.649656     4
#> 5:     5     7     0 6.374638     5

unlink(tfcsv1)
unlink(tfcsv2)