Imports a track from a file or data-frame.
emr_track.import(
track,
space,
categorical,
src,
override = FALSE,
remove_unknown = FALSE
)
the name of the newly created track
db dir string (path), one of the paths supplied in emr_db.connect
if 'TRUE' track is marked as categorical
file name or data-frame containing the track records
Boolean indicating whether the creation intends to override an existing track (default FALSE)
if 'TRUE', removes unknown ids (ids that are not present at 'patients.dob' track) from the data. Otherwise, an error is thrown.
None.
This function creates a new track from a text file or a data-frame. The location of the track is controlled via 'space' parameter which can be any of the db_dirs supplied in emr_db.connect.
If 'src' is a file name, the latter must be constituted of four columns separated by spaces or 'TAB' characters: ID, time, reference and value. The file might contain lines of comments which should start with a '#' character.
Alternatively 'src' can be an ID-Time Values table, which is a data frame with the following columns: "id" "time" "ref" and "value". Note that the file should not contain a header.
(see "User Manual" for more info).
emr_db.init_examples()
#> NULL
# import from data frame
emr_track.import(
"new_track",
categorical = TRUE,
src = data.frame(id = c(5, 10), time = c(1, 2), value = c(10, 20))
)
#> NULL
# import from file
fn <- tempfile()
write.table(
data.frame(id = c(5, 10), time = c(1, 2), reference = c(1, 1), value = c(10, 20)),
file = fn, sep = "\t", row.names = FALSE, col.names = FALSE
)
emr_track.import("new_track1", categorical = TRUE, src = fn)
#> NULL
# create an empty track
emr_track.import(
"empty_track",
categorical = TRUE,
src = data.frame(id = numeric(), time = numeric(), value = numeric())
)
#> NULL