Skip to content

Commit

Permalink
Fixed issue 05290: Export to R incorrectly changes results to factors…
Browse files Browse the repository at this point in the history
… for numeric input questions

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@12179 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Andrie de Vries committed Jan 24, 2012
1 parent ab4bf79 commit 22bde3b
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions admin/export_data_r.php
Expand Up @@ -66,7 +66,7 @@
'R'=>Array('name'=>'Ranking','size'=>1,'SPSStype'=>'F'),
'S'=>Array('name'=>'Short free text','size'=>1,'SPSStype'=>'F'),
'Y'=>Array('name'=>'Yes/No','size'=>1,'SPSStype'=>'F'),
':'=>Array('name'=>'Multi flexi numbers','size'=>1,'SPSStype'=>'F','Scale'=>3),
':'=>Array('name'=>'Multi flexi numbers','size'=>1,'SPSStype'=>'F'),
';'=>Array('name'=>'Multi flexi text','size'=>1,'SPSStype'=>'A'),
'*'=>Array('name'=>'Equation','size'=>1,'SPSStype'=>'A'),
);
Expand Down Expand Up @@ -195,25 +195,25 @@
$i = 1;
foreach ($fields as $field)
{
if($field['SPSStype'] == 'DATETIME23.2') $field['size']='';
if($field['SPSStype'] == 'DATETIME23.2') $field['size']='';
if($field['LStype'] == 'N' || $field['LStype']=='K')
{
$field['size'].='.'.($field['size']-1);
}
$field['size'].='.'.($field['size']-1);
}
switch ($field['SPSStype'])
{
case 'F':
$type="numeric";
break;
case 'A':
$type="character";
break;
case 'DATETIME23.2':
case 'SDATE':
$type="character";
//@TODO set $type to format for date
break;
}
case 'F':
$type="numeric";
break;
case 'A':
$type="character";
break;
case 'DATETIME23.2':
case 'SDATE':
$type="character";
//@TODO set $type to format for date
break;
}

if (!$field['hide'])
{
Expand All @@ -225,38 +225,40 @@
htmlspecialchars_decode(
mb_substr(
strip_tags_full(
$field['VariableLabel']),0,$length_varlabel))) // <AdV> added htmlspecialchars_decode
$field['VariableLabel']),0,$length_varlabel)))
. '"' . "\n";

// Create the value Labels!
if (isset($field['answers']))
{
$answers = $field['answers'];
//print out the value labels!
// data$V14=factor(data$V14,levels=c(1,2,3),labels=c("Yes","No","Uncertain"))
echo 'data[, ' . $i .'] <- factor(data[, ' . $i . '], levels=c(';
$str="";
foreach ($answers as $answer) {
if ($field['SPSStype']=="F" && my_is_numeric($answer['code'])) {
$str .= ",{$answer['code']}";
} else {
$str .= ",\"{$answer['code']}\"";
if($field['LStype'] != ':') // Exclude array (numeric) type questions. There must be a better way of doing this, but I can't find it. (AdV)
{
echo 'data[, ' . $i .'] <- factor(data[, ' . $i . '], levels=c(';
$str="";
foreach ($answers as $answer) {
if ($field['SPSStype']=="F" && my_is_numeric($answer['code'])) {
$str .= ",{$answer['code']}";
} else {
$str .= ",\"{$answer['code']}\"";
}
}
}
$str = mb_substr($str,1);
echo $str . '),labels=c(';
$str="";
foreach ($answers as $answer) {
$str .= ",\"{$answer['value']}\"";
}
$str = mb_substr($str,1);
$str = mb_substr($str,1);
echo $str . '),labels=c(';
$str="";
foreach ($answers as $answer) {
$str .= ",\"{$answer['value']}\"";
}
$str = mb_substr($str,1);
if($field['scale']!=='' && $field['scale'] == 2 ) {
$scale = ",ordered=TRUE";
} else {
$scale = "";
$scale = ",ordered=TRUE";
} else {
$scale = "";
}
echo "$str)$scale)\n";
}
echo "$str)$scale)\n";
}
}

//Rename the Variables (in case somethings goes wrong, we still have the OLD values
if (isset($field['sql_name']))
Expand Down

0 comments on commit 22bde3b

Please sign in to comment.