View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
13778Bug reportsImport/Exportpublic2019-05-13 14:10
ReporterPlano Assigned Todominikvitt 
PrioritynoneSeveritypartial_block 
Status closedResolutionfixed 
Product Version3.9.x 
Fixed in Version3.11.x 
Summary13778: Exporting data to the most recent version of R leads to incorrect data
Description

This problems applies to the matrix questions, where not all options are labelled (e.g. only the extreme anchors got labels, while the middle points don't have any labels.) The generate R-code will collapse all non-labeled options into one option.
The problem are the following lines in the R-Export code:
data[, 6] <- as.numeric(data[, 6])
attributes(data)$variable.labels[6] <- "[Do you win the lottery this friday]"
data[, 6] <- factor(data[, 6], levels=c(1,2,3,4,5),labels=c("very probable", "", "", "", "very unprobable"))

R handels labels completely different, compared to SPSS. The man page of the factor command https://stat.ethz.ch/R-manual/R-devel/library/base/html/factor.html explains the label option as:

labels

either an optional character vector of labels for the levels (in the same order as levels after removing those in exclude), or a character string of length 1. Duplicated values in labels can be used to map different values of x to the same factor level.

Additional Information

As a workaround, I programmed the following R function:

factor_lime <- function(x, levels, labels, ...){
if (length(levels) != length(unique(labels))){
return(x)
}else
{return(factor(x, levels = levels, labels = labels, ...))}
}
and I replaced all factor commands with factor_lime

TagsNo tags attached.
Attached Files
Bug heat8
Complete LimeSurvey version number (& build)3.9.0 (180604)
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMaraDB
Server OS (if known)Debian Stretch
Webserver software & version (if known)Apache2
PHP VersionPHP 7

Users monitoring this issue

Plano

Activities

DenisChenu

DenisChenu

2018-06-14 12:37

developer   ~48106

Last edited: 2018-06-14 12:38

If you have
data[, 6] <- factor(data[, 6], levels=c(1,2,3,4,5),labels=c("very probable", " ", " ", " ", "very unprobable"))

in the data (adding a space for each label) : it fix the issue ?

(really time to move R and SPPS to seperate plugin …)

Plano

Plano

2018-06-14 22:54

reporter   ~48117

No, this would not fix the problem. As long as there are labels with the same value, R will treat them as equal. One way of fixing it, would be the following code:
data[, 6] <- factor(data[, 6], levels=c(1,2,3,4,5),labels=c("1 very probable", "2 ", "3 ", "4", "5 very unprobable"))
That way you would get unique labels and still keep all information from the questionaire.
Plano

guest

guest

2018-06-15 14:58

viewer   ~48160

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&amp;id=27434

DenisChenu

DenisChenu

2018-06-15 17:57

developer   ~48183

@Plano : question about « No, this would not fix the problem. As long as there are labels with the same value, R will treat them as equal. One way of fixing it, would be the following code:»
If you have for label
'Great','Something','Great' : it broke too ?

Then we must ALWAYS add the code ? Right ?

Plano

Plano

2018-06-15 18:06

reporter   ~48185

Yes this would brake the code too. While I'm not sure how often this problem arrises, adding always the code seems a good idea.

Related Changesets

LimeSurvey: master d9f60ac4

2018-06-15 14:58:43

Dominik Vitt

Details Diff
Fixed issue 13778: Exporting data to the most recent version of R leads to incorrect data Affected Issues
13778
mod - application/core/plugins/ExportR/RSyntaxWriter.php Diff File

Issue History

Date Modified Username Field Change
2018-06-14 11:59 Plano New Issue
2018-06-14 11:59 Plano File Added: survey_archive_417723.lsa
2018-06-14 12:37 DenisChenu Note Added: 48106
2018-06-14 12:37 DenisChenu Note Edited: 48106
2018-06-14 12:38 DenisChenu Note Edited: 48106
2018-06-14 22:54 Plano Note Added: 48117
2018-06-15 14:16 c_schmitz Assigned To => dominikvitt
2018-06-15 14:16 c_schmitz Status new => assigned
2018-06-15 14:58 Changeset attached => LimeSurvey master d9f60ac4
2018-06-15 14:58 guest Note Added: 48160
2018-06-15 14:58 guest Resolution open => fixed
2018-06-15 15:00 dominikvitt Status assigned => resolved
2018-06-15 15:00 dominikvitt Fixed in Version => 3.11.x
2018-06-15 15:30 markusfluer Status resolved => closed
2018-06-15 17:57 DenisChenu Note Added: 48183
2018-06-15 18:05 Plano Issue Monitored: Plano
2018-06-15 18:06 Plano Status closed => feedback
2018-06-15 18:06 Plano Resolution fixed => reopened
2018-06-15 18:06 Plano Note Added: 48185
2019-05-13 14:09 dominikvitt Status feedback => closed
2019-05-13 14:10 dominikvitt Status closed => resolved
2019-05-13 14:10 dominikvitt Resolution reopened => fixed
2019-05-13 14:10 dominikvitt Status resolved => closed
2021-08-02 21:32 guest Bug heat 6 => 8