Skip to content

Commit

Permalink
Fixed issue #10586: Multiple choice exported to R, levels are wrong o…
Browse files Browse the repository at this point in the history
…n factor() syntax file
  • Loading branch information
c-schmitz committed Apr 4, 2016
1 parent 295eca8 commit ef17ba3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions application/core/plugins/ExportR/RDataWriter.php
Expand Up @@ -8,7 +8,7 @@ class RDataWriter extends CsvWriter {
* @var string
*/
public $na = '';

public $fieldmap = null;

public function init(\SurveyObj $survey, $sLanguageCode, \FormattingOptions $oOptions) {
Expand All @@ -20,7 +20,7 @@ public function init(\SurveyObj $survey, $sLanguageCode, \FormattingOptions $oOp
$this->doHeaders = true;

$oOptions->answerFormat = "short"; // force answer codes

// Save fieldmap so we can use it in transformResponseValue
$this->fieldmap = $survey->fieldMap;
}
Expand Down Expand Up @@ -54,15 +54,15 @@ protected function transformResponseValue($value, $fieldType, FormattingOptions
return 3;
}
break;

case 'G': // Gender question
if ($value == 'F') {
return 1;
} elseif ($value == 'M') {
return 2;
}
break;

case 'M': // Multiple choice
case 'P':
if (!empty($column) && isset($this->fieldmap[$column])) {
Expand All @@ -72,17 +72,17 @@ protected function transformResponseValue($value, $fieldType, FormattingOptions
return $value;
}
}

if ($value == 'Y') { // Yes
return 2;
return 1;
} elseif ($value === '') { // No
return 1;
return 0;
} else { // Not shown
return $this->na;
}
break;

case 'Y': // Yes no question
case 'Y': // Yes no question
if ($value == 'Y') {
return 1;
} elseif ($value == 'N') {
Expand Down

0 comments on commit ef17ba3

Please sign in to comment.