r - What is the difference between these files? -
r - What is the difference between these files? -
i writing r script programme qualtrics survey excel template created. grab survey items excel template via xlsx
bundle , bit of munging create .txt
file formatted way want it. problem can't upload qualtrics unless select in resulting .txt
file, copy, , paste blank .txt
file.
this not question qualtrics, per se, , don't think 1 needs know platform consider question. believe problem in r output file format. hope if go on reading, see mean.
everything in next code block should work.
require(xlsx) # import survey file; dropbox link above survey <- read.xlsx("template.xlsx", "survey") survey <- subset(survey, !is.na(survey$questiontext)) # drop if blank choices <- read.xlsx("template.xlsx", "choices") # create vector hold results output <- "[[advancedformat]]" # loop through every question (i in 1:nrow(survey)) { # insert start block if 1 exists bs <- ifelse(is.na(survey$blockname[i]), "", paste0("[[block:", as.character(survey$blockname[i]), "]]")) # insert end block if 1 exists <- ifelse(is.na(survey$endblock[i]), "", as.character(survey$endblock[i])) # insert item id if 1 exists qid <- ifelse(is.na(survey$questionid[i]), "", paste0("[[id:", as.character(survey$questionid[i]), "]]")) # subset selection sheet selected selection choices.sub <- subset(choices, choices$listname==survey$choicelist[i]) responses <- "" # create vector of choices (ch in 1:nrow(choices.sub)) { responses <- paste(responses, choices.sub$label[ch], sep="\r") } # insert page break if 1 exists pb <- ifelse(is.na(survey$pagebreak[i]) | i==nrow(survey), "", as.character(survey$pagebreak[i])) # add together output vector output <- paste(output, bs, survey$questiontype[i], qid, survey$questiontext[i], survey$choicetype[i], responses, pb, be, sep="\r") } # write txt file cat(output, file = (con <- file("foo1.txt", "w", encoding = "utf-8"))); close(con)
here's resulting foo1.txt file r. qualtrics rejects file. if select file , re-create new blank .txt
file (using st3), foo2.txt, qualtrics happy.
what different these 2 files? i'm not changing in foo2.txt
. copy/paste new file.
@carlwitthoft pointed me in right direction comment:
this conflict between <cr>
, <cr>-<lf>
end-of-line terminators.
i searched on topic , found so thread led me alter \r
\n
. did trick.
r qualtrics
Comments
Post a Comment