load.svy: load odk data from files

Description Usage Arguments Details Value Note Examples

View source: R/load.R

Description

load.svy takes a data file and a metadata file and returns a svy object.

Usage

1
2
load.svy(data, form = sub("_[0-9_]+.csv", ".json", data),
  update.fun = identity, check.names = TRUE, include.repeats = FALSE)

Arguments

data

a filename containing the survey data in csv format

form

a filename containing the survey metadata in json format

update.fun

an optional function to modify the raw data

Details

The data file is read into a data frame. Then the optional update.fun is run on the data.frame to incorporate post-collection corrections or updates. This function should not add choices or make any other changes to the meta data or the attributes of the data.frame or its columns. It should simply take the data.frame as its only argument and return the updated data.frame in the same format, as if it had just been read from file.

The metadata file is parsed into a list using fromJSON and the questions are extracted recursively using extract on the top level children element. For each question, data is retrieved from the corresponding column(s) of the data.frame and appended to the survey, and the metadata is appended to the data's attributes (see svq). The data is either a vector or a matrix, depending on the question type (see extract)

Finally the elements of metadata list (except children) are appended to the attributes of the resultant data.frame

Value

an object of class svy inheriting from data.frame, where each column is an object of class svq of a type appropriate to the question type

Note

The default parameters of this function are meant to function with formhub file naming conventions.

Examples

1
2
3
4
## Not run: 
load.svy("mysurvey_2015_05_01_05_31_27.csv")

## End(Not run)

mlgrm/svyr documentation built on May 11, 2017, 9:57 p.m.