Skip to content

Commit

Permalink
Fixed issue 06894: Data export in R syntax file for ranking type ques…
Browse files Browse the repository at this point in the history
…tions omits answer labels causing R data import failure

Dev export.php In function exportr() set $length_vallabel to 120, to prevent blank answer field
Fixed issue 07243: Syntax error in sytax file for R
Dev export.php In function exportr() changed read.csv() arguments
  • Loading branch information
andrie committed Jan 29, 2013
1 parent dcf048f commit 88f500d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -8,4 +8,5 @@
/tmp/*.lss
/tmp/*.png
/tmp/*.xls
/upload/.htaccess
/upload/.htaccess
/nbproject
31 changes: 16 additions & 15 deletions application/controllers/admin/export.php
Expand Up @@ -602,7 +602,7 @@ public function exportr()

//$typeMap = $this->_getTypeMap();

// $length_vallabel = '120'; // Set the max text length of Value Labels
$length_vallabel = '120'; // Set the max text length of Value Labels
$iLength = '25500'; // Set the max text length of Text Data
$length_varlabel = '25500'; // Set the max text length of Variable Labels
$headerComment = '';
Expand Down Expand Up @@ -671,7 +671,7 @@ public function exportr()

echo $headerComment;

echo ('data <- read.csv("survey_' . $iSurveyID .'_R_data_file.csv", na.strings=c(",", "\"\""), stringsAsFactors=FALSE)');
echo ('data <- read.csv("survey_' . $iSurveyID .'_R_data_file.csv", quote = "\'\"", na.strings=c("", "\"\""), stringsAsFactors=FALSE)');
echo ("\n\n");

// Build array that has to be returned
Expand Down Expand Up @@ -744,18 +744,19 @@ public function exportr()

if ( ! $field['hide'] )
{
echo("# LimeSurvey Field type: $field[SPSStype]\n");
echo "data[, " . $i . "] <- "
. "as.$type(data[, " . $i . "])\n";

echo 'attributes(data)$variable.labels[' . $i . '] <- "'
. addslashes(
htmlspecialchars_decode(
mb_substr(
stripTagsFull(
$field['VariableLabel']
), 0, $length_varlabel
)
)
htmlspecialchars_decode(
mb_substr(
stripTagsFull(
$field['VariableLabel']
), 0, $length_varlabel
)
)
)
. '"' . "\n";

Expand All @@ -779,28 +780,28 @@ public function exportr()
$str .= ",\"{$answer['code']}\"";
}
}

$str = mb_substr($str, 1);
echo $str . '),labels=c(';
$str = "";

$str = "";
foreach ( $answers as $answer )
{
$str .= ",\"{$answer['value']}\"";
$str .= ", \"{$answer['value']}\"";
}

$str = mb_substr($str, 1);
$str = mb_substr($str, 2); // Remove leading comma and space

if ( $field['scale'] !== '' && $field['scale'] == 2 )
{
$scale = ",ordered=TRUE";
$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
Expand Down

0 comments on commit 88f500d

Please sign in to comment.