defRead: Read external csv data set definitions

Description Usage Arguments Value See Also Examples

View source: R/define_data.R

Description

Read external csv data set definitions

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

unlink(tfcsv)

# Generate data based on external definition

genData(5, defs)

Example output

   varname       formula variance      dist     link
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
   myID nr x1       y1 y2
1:    1  7  0 2.828767  7
2:    2  7  1 6.071156  7
3:    3  7  1 9.594372  6
4:    4  7  0 7.219479  6
5:    5  7  0 8.835160  7

simstudy documentation built on Oct. 23, 2020, 6:55 p.m.