This project is read-only.

Raw output from R

Mar 4, 2015 at 12:03 AM
Edited Mar 4, 2015 at 12:03 AM
Hello,

I am currently trying to return the output from R exactly the way R would show in its console.

I am open to any method that works.

I tried using GenericVectors and iterating through it but the output was not organized very well for some of the outputs.

I would prefer to use something like sink() but the text file is empty.
I currently changed the code to something very simple to help ensure there is no error in the R code.

I tried to run it directly from C#:
            ThisAddIn.engine.Evaluate("sink('c:/temp/out.txt')");
            ThisAddIn.engine.Evaluate("dt<-c(3,3,4,4,5,5,6,6)");
            ThisAddIn.engine.Evaluate("h<-hist(dt)");
            ThisAddIn.engine.Evaluate("h");
            ThisAddIn.engine.Evaluate("sink()");
And I have tried to put the code in a file
            ThisAddIn.engine.Evaluate(@"source('C:/Users/default/Desktop/test.r')");
but the results are the same.
I get the Histogram graph which displays fine.
And the text file gets created and the date modified gets updated.
but the text file itself is empty inside.

Any suggestions would be very helpful.

Thanks!
Mar 8, 2015 at 11:04 PM
Edited Mar 8, 2015 at 11:04 PM
Try ThisAddIn.engine.AutoPrint = true before evaluating any R code. Manually needing to enable AutoPrint is a 'by design' bevhavior of the REngine. You can find out more in the R team's R-Internals document, Chapter 1.6: http://cran.r-project.org/doc/manuals/r-release/R-ints.html#Autoprinting

Blue Skies,
Ritch
Mar 9, 2015 at 11:55 PM
It works!

I spent a lot of time trying to get this to work.
Thanks a bunch!
Mar 10, 2015 at 11:09 PM
Happy to help. Come back if you run into anymore issues.