Cant source another R script

Mar 7, 2013 at 4:26 PM
Just for testing purposes I'm simply doing the following:
StringWriter sw = new StringWriter();
      return Engine.Evaluate("source(file.path(\"C:/Users/me/Desktop/RDotNetTest/test.R\"))");
catch (ParseException)
      throw new Exception(sw.ToString());
my R script is very simple and is just :
a <- c(1,2,3)
Its throwing the following exception:
"{Error in file(file, "r", encoding = encoding) : 4 arguments passed to .Internal(file) which requires 5}"

Any ideas?
Mar 9, 2013 at 9:44 PM
This is odd. Your code looks fine, and the following works for me as expected.
            var a = engine.Evaluate("a").AsNumeric().ToArray();
While not a perfect match ('file' vs 'filename') it looks like the call to 'source' fails at:
            file <- file(filename, "r", encoding = encoding)
as of 2.15.0 (and probably for a long time) all arguments to the file function have default values, so the error message about a missing argument is very unexpected. Can you run in R actually?
file(description = "", open = "", blocking = TRUE,
     encoding = getOption("encoding"), raw = FALSE)
Mar 11, 2013 at 9:57 AM

Thanks for your reply. I found out what the problem was and thought it best to explain in case someone else has the same problem. I have 2 versions of R installed on my machine(2.14.1 and 2.9.0). I was setting the path variable to 2.14.1 version but it seemed the engine was getting the home path from the 2.9.0 version and I believe it was looking in a drive I don't even have for the libs path? After I specified the R_LIBS and R_HOME paths it all worked fine.

                // Set the folder in which R.dll locates.
                var envPath = Environment.GetEnvironmentVariable("PATH");
                var rBinPath = @"C:\Program Files\R\R-2.14.1\bin\i386";
                Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
                Environment.SetEnvironmentVariable("R_LIBS", @"C:\Program Files\R\R-2.14.1\library");
                Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-2.14.1");
                engine = REngine.CreateInstance("RDotNet");
Mar 12, 2013 at 11:49 PM
Thank you for sharing this; this is really useful and confirms the recurrent difficulties with R environment variriables depending on the platforms and user setups.