View Issue Details

This bug affects 1 person(s).
 6
IDProjectCategoryView StatusLast Update
19889Bug reportsImport/Exportpublic2024-12-13 15:32
Reportericeclimber81 Assigned To 
PrioritynoneSeverityminor 
Status newResolutionopen 
Product Version6.6.x 
Summary19889: Exporting response data to R does not honor the choice of "answer codes" or "full answers" for responses
Description

When exporting response data in R format, LS will produce identical export files (.R syntax and R data .csv) irrespective of whether "answer codes" or "full answers" is chosen as the response data format.

Because the answer codes are always overwritten by the full answer text in the R syntax file, answer codes are never accessible to the analyst.

Steps To Reproduce

Steps to reproduce

  1. Export results > 2. Export format [choose 'R syntax file'] > 3. Responses [choose 'answer codes'] > 4. Export
    Repeat but choose 'R data file' as Export format in step 2
    To experiment, repeat with choosing 'full answers' in step 3

Expected result

To be able to work with 'answer codes' as the response format, the R syntax file would need to repeat what's in the factor LEVELS for the factor LABELS, like so:

data[, 8] <- factor(data[, 8], levels=c("a","b","c"),labels=c("a", "b", "c"))

Actual result

LS always generates identical R syntax (.R) and R data files (.csv), irrespective of the response format chosen (answer codes or full answers). In the R syntax file, this is an example of the problem:

data[, 8] <- factor(data[, 8], levels=c("a","b","c"),labels=c("Option A", "Option B", "Option C"))

Explained: The way R works, the factor labels (= full answers, e.g. "Option A", "Option B", "Option C") will effectively overwrite the factor levels (= answer codes, e.g. "a","b","c"), as explained here (https://stackoverflow.com/a/5869675/5389846), making them inaccessible. This is different from how levels and labels work in SPSS.

TagsNo tags attached.
Attached Files
TEST_syntax_file_AnswerCodes.R (1,923 bytes)   
data <- read.csv("survey_599469_R_data_file.csv", quote = "'\"", na.strings=c("", "\"\""), stringsAsFactors=FALSE, fileEncoding="UTF-8-BOM")


# LimeSurvey Field type: F
data[, 1] <- as.numeric(data[, 1])
attributes(data)$variable.labels[1] <- "id"
names(data)[1] <- "id"
# LimeSurvey Field type: DATETIME23.2
data[, 2] <- as.character(data[, 2])
attributes(data)$variable.labels[2] <- "submitdate"
names(data)[2] <- "submitdate"
# LimeSurvey Field type: F
data[, 3] <- as.numeric(data[, 3])
attributes(data)$variable.labels[3] <- "lastpage"
names(data)[3] <- "lastpage"
# LimeSurvey Field type: A
data[, 4] <- as.character(data[, 4])
attributes(data)$variable.labels[4] <- "startlanguage"
names(data)[4] <- "startlanguage"
# LimeSurvey Field type: A
data[, 5] <- as.character(data[, 5])
attributes(data)$variable.labels[5] <- "seed"
names(data)[5] <- "seed"
# LimeSurvey Field type: DATETIME23.2
data[, 6] <- as.character(data[, 6])
attributes(data)$variable.labels[6] <- "startdate"
names(data)[6] <- "startdate"
# LimeSurvey Field type: DATETIME23.2
data[, 7] <- as.character(data[, 7])
attributes(data)$variable.labels[7] <- "datestamp"
names(data)[7] <- "datestamp"
# LimeSurvey Field type: A
data[, 8] <- as.character(data[, 8])
attributes(data)$variable.labels[8] <- "Single choice question with answer codes and labels (code a/b/c):"
data[, 8] <- factor(data[, 8], levels=c("a","b","c"),labels=c("Option A", "Option B", "Option C"))
names(data)[8] <- "Q00"
# LimeSurvey Field type: F
data[, 9] <- as.numeric(data[, 9])
attributes(data)$variable.labels[9] <- "Yes/No question (code 1/0):"
data[, 9] <- factor(data[, 9], levels=c(1,0),labels=c("Yes", "No"))
names(data)[9] <- "Q01"
# LimeSurvey Field type: A
data[, 10] <- as.character(data[, 10])
attributes(data)$variable.labels[10] <- "Yes/No question (code Y/N):"
data[, 10] <- factor(data[, 10], levels=c("Y","N"),labels=c("Yes", "No"))
names(data)[10] <- "Q02"
TEST_syntax_file_AnswerCodes.R (1,923 bytes)   
TEST_syntax_file_FullAnswers.R (1,923 bytes)   
data <- read.csv("survey_599469_R_data_file.csv", quote = "'\"", na.strings=c("", "\"\""), stringsAsFactors=FALSE, fileEncoding="UTF-8-BOM")


# LimeSurvey Field type: F
data[, 1] <- as.numeric(data[, 1])
attributes(data)$variable.labels[1] <- "id"
names(data)[1] <- "id"
# LimeSurvey Field type: DATETIME23.2
data[, 2] <- as.character(data[, 2])
attributes(data)$variable.labels[2] <- "submitdate"
names(data)[2] <- "submitdate"
# LimeSurvey Field type: F
data[, 3] <- as.numeric(data[, 3])
attributes(data)$variable.labels[3] <- "lastpage"
names(data)[3] <- "lastpage"
# LimeSurvey Field type: A
data[, 4] <- as.character(data[, 4])
attributes(data)$variable.labels[4] <- "startlanguage"
names(data)[4] <- "startlanguage"
# LimeSurvey Field type: A
data[, 5] <- as.character(data[, 5])
attributes(data)$variable.labels[5] <- "seed"
names(data)[5] <- "seed"
# LimeSurvey Field type: DATETIME23.2
data[, 6] <- as.character(data[, 6])
attributes(data)$variable.labels[6] <- "startdate"
names(data)[6] <- "startdate"
# LimeSurvey Field type: DATETIME23.2
data[, 7] <- as.character(data[, 7])
attributes(data)$variable.labels[7] <- "datestamp"
names(data)[7] <- "datestamp"
# LimeSurvey Field type: A
data[, 8] <- as.character(data[, 8])
attributes(data)$variable.labels[8] <- "Single choice question with answer codes and labels (code a/b/c):"
data[, 8] <- factor(data[, 8], levels=c("a","b","c"),labels=c("Option A", "Option B", "Option C"))
names(data)[8] <- "Q00"
# LimeSurvey Field type: F
data[, 9] <- as.numeric(data[, 9])
attributes(data)$variable.labels[9] <- "Yes/No question (code 1/0):"
data[, 9] <- factor(data[, 9], levels=c(1,0),labels=c("Yes", "No"))
names(data)[9] <- "Q01"
# LimeSurvey Field type: A
data[, 10] <- as.character(data[, 10])
attributes(data)$variable.labels[10] <- "Yes/No question (code Y/N):"
data[, 10] <- factor(data[, 10], levels=c("Y","N"),labels=c("Yes", "No"))
names(data)[10] <- "Q02"
TEST_syntax_file_FullAnswers.R (1,923 bytes)   
TEST_data_file_AnswerCodes.csv (974 bytes)   
"id. Response ID","submitdate. Date submitted","lastpage. Last page","startlanguage. Start language","seed. Seed","startdate. Date started","datestamp. Date last action","Q00. Single choice question with answer codes and labels (code a/b/c):","Q01. Yes/No question (code 1/0):","Q02. Yes/No question (code Y/N):","interviewtime. Total time","groupTime577. Group time: My first question group","Q00Time. Question time: Q00","Q01Time. Question time: Q01","Q02Time. Question time: Q02"
"1","2024-12-13 11:59:08","1","en","1331703622","2024-12-13 11:58:59","2024-12-13 11:59:08","a","0","Y","9.01","9.01",,,
"2","2024-12-13 11:59:17","1","en","971659123","2024-12-13 11:59:11","2024-12-13 11:59:17","b","1","N","6.91","6.91",,,
"3","2024-12-13 11:59:26","1","en","1262037335","2024-12-13 11:59:21","2024-12-13 11:59:26","c","0","Y","5.26","5.26",,,
"4","2024-12-13 11:59:57","1","en","2012052566","2024-12-13 11:59:52","2024-12-13 11:59:57","b","0","N","5.97","5.97",,,
TEST_data_file_FullAnswers.csv (834 bytes)   
"Response ID","Date submitted","Last page","Start language","Seed","Date started","Date last action","Single choice question with answer codes and labels (code a/b/c):","Yes/No question (code 1/0):","Yes/No question (code Y/N):","Total time","Group time: My first question group","Question time: Q00","Question time: Q01","Question time: Q02"
"1","2024-12-13 11:59:08","1","en","1331703622","2024-12-13 11:58:59","2024-12-13 11:59:08","a","0","Y","9.01","9.01",,,
"2","2024-12-13 11:59:17","1","en","971659123","2024-12-13 11:59:11","2024-12-13 11:59:17","b","1","N","6.91","6.91",,,
"3","2024-12-13 11:59:26","1","en","1262037335","2024-12-13 11:59:21","2024-12-13 11:59:26","c","0","Y","5.26","5.26",,,
"4","2024-12-13 11:59:57","1","en","2012052566","2024-12-13 11:59:52","2024-12-13 11:59:57","b","0","N","5.97","5.97",,,
Bug heat6
Complete LimeSurvey version number (& build)6.8.2
I will donate to the project if issue is resolvedNo
Browser
Database type & versionLS Cloud Hosting
Server OS (if known)
Webserver software & version (if known)
PHP VersionInfo not visible

Users monitoring this issue

DenisChenu

Activities

DenisChenu

DenisChenu

2024-12-13 15:26

developer   ~81625

Oh ! Complex situation

R data cabn be same , but allow R syntax to use
data[, 8] <- factor(data[, 8], levels=c("a","b","c"),labels=c("a", "b", "c"))
?

iceclimber81

iceclimber81

2024-12-13 15:32

reporter   ~81626

Yes, exactly, the R data file can be the same (it's a .CSV with only 'answer codes' for both response format types, answer code and full answers), but the R syntax file must be different so it doesn't overwrite the answer codes.

Issue History

Date Modified Username Field Change
2024-12-13 12:32 iceclimber81 New Issue
2024-12-13 12:32 iceclimber81 File Added: TEST_survey_archive.lsa
2024-12-13 12:32 iceclimber81 File Added: TEST_syntax_file_AnswerCodes.R
2024-12-13 12:32 iceclimber81 File Added: TEST_syntax_file_FullAnswers.R
2024-12-13 12:32 iceclimber81 File Added: TEST_data_file_AnswerCodes.csv
2024-12-13 12:32 iceclimber81 File Added: TEST_data_file_FullAnswers.csv
2024-12-13 14:59 DenisChenu Issue Monitored: DenisChenu
2024-12-13 14:59 DenisChenu Bug heat 0 => 2
2024-12-13 15:26 DenisChenu Note Added: 81625
2024-12-13 15:26 DenisChenu Bug heat 2 => 4
2024-12-13 15:32 iceclimber81 Note Added: 81626
2024-12-13 15:32 iceclimber81 Bug heat 4 => 6