## load raw CAM data set
rawCAMfile <- vroom::vroom(
file = "data/CAMspiracy_data.txt",
delim = "\t",
show_col_types = FALSE,
col_names = FALSE)$X1
raw_CAM <- list()
for(i in 1:length(rawCAMfile)){
if(testIfJson(rawCAMfile[[i]])) {
raw_CAM[[i]] <- jsonlite::fromJSON(txt = rawCAMfile[[i]])
}else{
print("ERROR")
break
}
}
## load .xlsx file containing unique prolific IDs and CAM IDs
dat_ids <- xlsx::read.xlsx2(file = "data/questionnaireCAMs_t2.xlsx", sheetIndex = 1)
dat_ids <- dat_ids[, c("CAM_ID", "PROLIFIC_PID")]
for(i in 1:length(raw_CAM)){
if(!(raw_CAM[[i]]$idCAM %in% dat_ids$CAM_ID)){
print("Error")
break
}else{
raw_CAM[[i]]$creator <- dat_ids$PROLIFIC_PID[dat_ids$CAM_ID %in% raw_CAM[[i]]$idCAM]
}
}
## save raw CAM data with unique IDs
setwd("data")
writeLines("", "CAMspiracy_data_fixed.txt") # create file
text_connection <- file("CAMspiracy_data_fixed.txt", "a") # open connection to append
for(i in 1:length(raw_CAM)){
writeLines(jsonlite::toJSON(x = raw_CAM[[i]]), text_connection)
}
close(text_connection) # close connection
### copy files (not overwritten)
tmp_file_from <- getwd()
setwd("../outputs")
file.copy(from = paste0(tmp_file_from, "/CAMspiracy_data_fixed.txt"), to = paste0(getwd(), "/CAMspiracy_data_fixed.txt"))