--- loncom/homework/lonr.pm	2009/08/14 01:58:52	1.9
+++ loncom/homework/lonr.pm	2024/06/21 23:42:49	1.12
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Interface routines to R CAS
 #
-# $Id: lonr.pm,v 1.9 2009/08/14 01:58:52 www Exp $
+# $Id: lonr.pm,v 1.12 2024/06/21 23:42:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,11 +33,8 @@ use IO::Socket;
 use Apache::lonnet;
 use Apache::response();
 use LONCAPA;
-
-### You need to install the libraries below for this to work!
-
-###use Tie::IxHash::Easy; # autoties all subhashes to keep index order
-###use Data::Dumper;  # used to output hash contents
+use Tie::IxHash::Easy; # autoties all subhashes to keep index order
+use Data::Dumper;  # used to output hash contents
 
 my $errormsg='';
 
@@ -56,7 +53,9 @@ sub Rcroak {
 #
 sub Rpeel {
         my $x = $_[0];  # the string containing the serialized R object(s)
-        if ($x =~ /^((?:i|d):(.+?);)(.*)$/) {
+        if ($x =~ /^N\;(.*)$/) {
+            return ('',$1);
+        } elsif ($x =~ /^((?:i|d):(.+?);)(.*)$/) {
                 return ($1, $+);  # x starts with a number
         } elsif ($x =~ /^s:(\d+):/) {
                 my $n = $1;  # x starts with a string of length n
@@ -150,6 +149,8 @@ sub Rreturn {
         }
         if ($errormsg) { return $errormsg; }
         return \%h;  # return a reference to the hash
+    } elsif ($x eq '') {
+        return '';
     } else {
         return 'Unrecognized output';
     }
@@ -242,9 +243,9 @@ sub blacklisted {
 }
 
 sub r_allowed_libraries {
-   return ('alr3','boot','car','class','cluster','datasets','Hmisc','KernSmooth','leaps','lmtest',
-           'MASS','methods','mgcv','nlme','nnet','qAnalyst','quadprog','rpart','SuppDists','spatial',
-           'splines','stats','stats4','survival','tseries','zoo');
+   return ('alr3','boot','car','class','cluster','datasets','FactoMineR','Hmisc','KernSmooth','leaps',
+           'lmtest','MASS','mdatools','methods','mgcv','nlme','nnet','qAnalyst','quadprog','rpart', 
+           'SuppDists','spatial','splines','stats','stats4','survival','tseries','zoo');
 }
 
 sub r_is_allowed_library {