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

Description Usage Arguments Note Examples

View source: R/data.frame.R

Description

Convert a dataframe to an ejObject

Usage

1
2
3
## S3 method for class 'data.frame'
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)

Note

We assume one row per record.

Examples

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

Hackout2/repijson documentation built on May 6, 2019, 9:48 p.m.