loadData: Load Data

Description Usage Arguments Details Value Examples

View source: R/importFunctions.R

Description

Reads data from an excel, R, or csv file and stores as a data frame. It can read labels from a separate csv file (labelFile), which can be generated from SPSS output. It can read double header csv files from Qualtrics output. Options to save data as a .csv or .R file.

Usage

1
2
loadData(dataFile, dputFile = NULL, labelFile = NULL, emptyStr = "#NULL!",
  saveCsv = FALSE, overrideDput = FALSE, twoHeader = FALSE, ...)

Arguments

dataFile

file path to data file (csv, R, xlsx, xls, sav supported)

dputFile

file path to .R data file (loading or saving). Default is to not save any file; 'same' indicates the same name and location as dataFile

labelFile

file path to .csv label file (From SPSS output)

emptyStr

character vector of strings to remove. By default, it removes the terrible "#NULL!" string that Excel puts in crazy places...

saveCsv

saves a .csv file if True (default is False)

overrideDput

if True, read .csv instead of .R file if both exist (default is False)

twoHeader

if False (default) there is only one header row in the dataFile. If True, it reads two header rows and returns the second row as a separate data frame. This affects the return value (see below). Set this to True if you are getting data from Qualtrics!

...

extra variables passed to read.xls, read.spss, or read.csv

Details

Note that converting Excel files requires python and an external python script (exceltocsv). It is best to manually convert the Excel file to .csv and then load it into R.

Value

By default, the main data frame is returned. If twoHeader is set to True, a list of two data frames is returned: the first element is the main data frame and the second is the 2nd header (Qualtrics questions) data frame. It is best to assign each to a separate variable (see examples)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
tf = paste0(tempfile(), '.csv')
write.csv(mtcars, tf)
dataFrame = loadData(tf)

# to read file from secure server:
dataFile = file.path(secureServer(), 'project/path/datafile.csv')

# To load data from Qualtrics:
qualtricsData = data.frame(Q1 = c('Question 1', 'A', 'B', 'C'),
                           Q2 = c('Question 2', '1', '2', '3'))
write.csv(qualtricsData, tf)
dataList = loadData(tf)
mainDataFrame = dataList[[1]]
questionsDataFrame = dataList[[2]]

mnblonsky/REMI documentation built on May 22, 2017, 11:57 a.m.