sink function has changed behavior from RDotNet 1.7 to 1.8.1
Here is a script that writes some text to the specified file using RDotNet 1.7 and the output file is empty using RDotNet 1.8.1 running the same script:
foo<-function(x,y){x+y}; attr(foo, 'comment') <- 'foo performs simple addition'; sink('c:/temp/result.txt'); attributes(foo); sink(NULL);
If a print function is added around attributes(foo), (i.e. foo<-function(x,y){x+y}; attr(foo, 'comment') <- 'foo performs simple addition'; sink('c:/temp/result.txt'); print(attributes(foo)); sink(NULL); )
the file will have the content.
Thanks for reporting this! Just to confirm - this is the same underlying version of R, just the version of R.NET that changed? Could I ask what version of R you experienced this with?
@lrasmus Running the script in R console will writes some text correctly. The problem shows up when updating RDotNet from 1.7 to 1.8.1. RDotNet 1.8.1 with either R 3.4 or R 3.5 will have the same problem.
Thanks @Wei-Lu!
May have some relation to #98 as well. Will dig in further on both of these issues to see what's going on. As noted in both issues, this is working fine from R console, just not in how we're interacting with the R engine.
@Wei-Lu, I think it's unrelated to #98 - I forgot there was a change more recently to turn off auto-printing. I think setting AutoPrint to true will re-enable this for you.
var engine = REngine.GetInstance();
engine.AutoPrint = true; // Add this line
@lrasmus Actually, it does not work after I added engine.AutoPrint = true;
I notice that I had print function around attributes(foo).
Argh! Too good to be true I guess. Let me check to see if I did something similar in my testing, otherwise I'll keep investigating.
EDIT - @Wei-Lu not sure how I mis-tested this so poorly, but confirmed I'm still seeing it as well. My sincere apologies. Looked at it over the weekend, and will continue investigating.
@lrasmus - Just to confirm that this does sound to be connected with the issues I have been experiencing relating to #98 . I was also able to replicate.
@Wei-Lu / @lrasmus - Just to let you know that the same also happens when plotting to files. As a workaround for now, I am wrapping all evaluations with the withAutoprint() function. Example when plotting:
engine.Evaluate("png('rplot.png')") rCommand = "ggplot(mtcars, aes(x='car name', y=mpg_z, label=mpg_z))" engine.Evaluate("withAutoprint({" + rCommand + "}, echo=TRUE)"); engine.Evaluate("dev.off()")
@MarkFleet - thanks for providing a workaround, sorry that it's still necessary. Unfortunately this one continues to stump me as to cause & solution.