repijson (version 0.1.0)

as.ejObject.data.frame: Convert a dataframe to an ejObject

Description

Convert a dataframe to an ejObject

Usage

"as.ejObject"(x, recordID = NA, recordAttributes, eventDefinitions, metadata = list(), ...)

Arguments

x
The dataframe to convert
recordID
an ID for the record, if NA one is created
recordAttributes
A character vector containing the names of the columns in the dataframe that are attributes of the record
eventDefinitions
A list of event definitions
metadata
A list of metadata ejAttribute objects describing the dataset
...
other parameters (to maintain consistency with the generic)

Examples

Run this code
#Here we use the toyll (toy line-list) data provided inside the package
data(toyll)
toyll
#Here we some data clean-up (make the date columns POSIX objects)
#Date-time conversion could be made automatic but introduces
#a big risk of mis-conversion so we leave this to the user
#to ensure that we don't silently corrupt their data

toyll$date.of.onset <- as.POSIXct(toyll$date.of.onset)
toyll$date.of.admission <- as.POSIXct(toyll$date.of.admission)
toyll$date.of.discharge <- as.POSIXct(toyll$date.of.discharge)
toyll$contact1.date <- as.POSIXct(toyll$contact1.date)
toyll$contact2.date <- as.POSIXct(toyll$contact2.date)
toyll$contact3.date <- as.POSIXct(toyll$contact3.date)

ind.fields <- c(names(toyll)[1:5], "hospital", "fever", "sleepy")
x <- as.ejObject(toyll,
                 recordAttributes=ind.fields,
                 eventDefinitions=list(
                 define_ejEvent(name="admission", date="date.of.admission"),
                 define_ejEvent(name="discharge", date="date.of.discharge"),
                 define_ejEvent(name="contact1", date="contact1.date", attributes="contact1.id"),
                 define_ejEvent(name="contact2", date="contact2.date", attributes="contact2.id"),
                 define_ejEvent(name="contact3", date="contact3.date", attributes="contact3.id")
                 ))
print(x)

Run the code above in your browser using DataLab