[LON-CAPA-cvs] cvs: loncom / lonr
raeburn
raeburn at source.lon-capa.org
Sun Nov 16 12:41:53 EST 2014
raeburn Sun Nov 16 17:41:53 2014 EDT
Modified files:
/loncom lonr
Log:
- Modify changes in rev 1.9 to explicitly separate the regexp which contributes
output from indexed lines, and the regexp which contributes output from
unserialized data.frame and matrix output (to support legacy code).
- Add some documentation.
Index: loncom/lonr
diff -u loncom/lonr:1.10 loncom/lonr:1.11
--- loncom/lonr:1.10 Sun Nov 16 15:35:27 2014
+++ loncom/lonr Sun Nov 16 17:41:53 2014
@@ -3,7 +3,7 @@
# The LearningOnline Network with CAPA
# Connect to R CAS
#
-# $Id: lonr,v 1.10 2014/11/16 15:35:27 raeburn Exp $
+# $Id: lonr,v 1.11 2014/11/16 17:41:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -351,12 +351,28 @@
return 'Error: '.$error;
}
+#
+# Extract data from lines returned by R:
+# including: (a) indexed output, e.g., line starts with [1] etc. (index excluded)
+# (b) support for legacy use of &cas("R") to retreve matrix and data.frame
+# i.e., unserialized data, in which lines may begin [1,] or 1
+# respectively. The approved method for retrieving these types of
+# data is to use &cas_hashref(), which uses phpSerialize() to
+# serialize the output (thereby eliminating the need for the second
+# regexp in the "elsif" when looping over the lines of output.
+# excluding: echo of actual (final) expression originally passed to R excluded by
+# checking for trailing semicolon.
+#
+
my $realoutput='';
foreach my $line (split(/\n/,$output)) {
$line=~s/\s$//gs;
if ($line=~/^Error\:/) { $syntaxerr=1; next; }
- if ($line=~ /\;$/) { next; }
- if (my ($result)=($line=~/^\s*\[?\d+\,?\]?\s*(.*)/)) { $realoutput.=$result."\n"; }
+ if (my ($result)=($line=~/^\s*\[\d+\]\s*(.*)/)) {
+ $realoutput.=$result."\n";
+ } elsif (($line !~ /\;$/) && (my ($result)=($line=~/^(?:\[\d+\,\]|\d+)\s*(.*)/))) {
+ $realoutput.=$result."\n";
+ }
}
if (wantarray) {
return ($realoutput,$syntaxerr);
More information about the LON-CAPA-cvs
mailing list