-
Notifications
You must be signed in to change notification settings - Fork 15
/
pull_firedata.R
40 lines (26 loc) · 1.71 KB
/
pull_firedata.R
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# require devtools and fireData packages
if (!require("devtools")) install.packages("devtools")
if (!require("fireData")) devtools::install_github("Kohze/fireData")
library(fireData) # https://github.com/Kohze/fireData
# secret key = zVIDsa5nmGLKDD73ymLIKkrdoNpGDrTC4nKe2KKa
# download all files from database
dataBackup(projectURL = "https://contingencypractice.firebaseio.com", #databaseURL
secretKey = "zVIDsa5nmGLKDD73ymLIKkrdoNpGDrTC4nKe2KKa", #Secret Key of the database
"./data/data.json") # file path of where to save the data (out default assumes cloning the GitHub repo)
# install.packages("jsonlite")
library("jsonlite")
#································To check the number of data points in the database ··············································
# open the file that was just downloaded
data<-unlist(jsonlite::fromJSON("./data/data.json"), recursive = FALSE, use.names = TRUE)
# install.packages("plyr")
library("plyr")
# collapse json levels
data<-rbind.fill(data)
#********************************************************************************************************************************
#*******************Data will still have json levels that need to be unpacked if you collected survey responses******************
#*******************One way to do this will be demonstrated in data_analysis.R***************************************************
#********************************************************************************************************************************
# number of subjects
length(unique(data$subject))
# save data to .csv file
write.csv(data, "./data/data.csv", row.names = FALSE)