formhubRead: Reads data from a passed csv filename and json filename into...

Description Usage Arguments Value Examples

View source: R/formhub.R

Description

This function creates a formhubData object from two files: a csv data file, and a json form file. These should both be downloaded from formhub.org for the same form.

Usage

1
2
3
formhubRead(csvfilename, jsonfilename, extraFormDF = data.frame(),
  dropCols = "", na.strings = c("n/a"), convert.dates = TRUE,
  keepGroupNames = TRUE)

Arguments

csvfilename

filename (or a connection object) that has the formhub data

jsonfilename

filename of a json file (or a connection object) that has the form.json form

extraFormDF

override the form (such as by providing a type for a calculate, a new label, etc.)

dropCols

a regular expression, any column name that matches that regexp will be dropped

na.strings

list of na.strings to be passed onto read.csv (default: "n/a")

keepGroupNames

for a question with name foo in group bar, keepGroupName=T will generate a name foo.bar, while keepGroupName=F will generate a name bar

Value

formhubDataObj a formhubData Object, with "data" and "form" slots

Examples

1
2
3
4
5
6
7
# will need to download data.csv and form.json for a specific form on formhub, for below, download
http://formhub.org/mberg/forms/good_eats/data.csv http://formhub.org/mberg/forms/good_eats/form.json
good_eats <- formhubRead("~/Downloads/good_eats_2013_05_05.csv", "~/Downloads/good_eats.json")
head(good_eats) # is a data frame of all the data
good_eatsX <- formhubRead("~/Downloads/good_eats_2013_05_05.csv", "~/Downloads/good_eats.json",
             extraFormDF=data.frame(name="imei", type="integer", label="IMEI"))
good_eatsX

prabhasp/formhub.R documentation built on May 25, 2019, 11:25 a.m.