Learn R Programming

OutbreakTools (version 0.1-16)

get.data: Access data in "obkData" objects

Description

get.data is a generic function with a method for '>obkData objects. It can be used to retrieve various information, known only by the name of the field looked for.

Usage

get.data(x, …)

# S4 method for obkData get.data(x, data, where=NULL, drop=TRUE, showSource=FALSE, …)

Arguments

x

an '>obkData object.

data

a character string indicating the name of the data field to look for.

where

an optional character string indicating the name of the slot in which the information should be looked for; if NULL, the method will look in all slots starting with @individuals, then @samples, and finally in @records.

drop

a logical indicating if a vector should be returned (TRUE), as opposed to a data.frame with on single column (FALSE).

showSource

a logical indicating if information about individualIDs and slot sources should be returned. If TRUE a dataframe with three columns will be returned, as opposed to a vector/single column if FALSE.

currently not used.

Examples

Run this code
# NOT RUN {
## LOAD DATA ##
data(ToyOutbreak)
ls()


## VARIOUS USE OF GET.DATA ##
# list all the data with name 'Sex' from the obkData object
get.data(ToyOutbreak, "Sex")

# list all the data with 'date' from the obkData object
get.data(ToyOutbreak, "date")
get.data(ToyOutbreak, "date", showSource=TRUE)
get.data(ToyOutbreak, "date", where="records")

# Extract from the obkData object a given field
x <- get.data(ToyOutbreak, "records")
names(x) # x contains the whole 'records' list
head(x$Fever)
x <- get.data(ToyOutbreak, "samples")
names(x) # x contains the whole 'samples' data.frame

# }

Run the code above in your browser using DataLab