rdotnet icon indicating copy to clipboard operation
rdotnet copied to clipboard

sink function has changed behavior from RDotNet 1.7 to 1.8.1

Open Wei-Lu opened this issue 6 years ago • 9 comments

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.

Wei-Lu avatar Jul 25 '19 23:07 Wei-Lu

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 avatar Jul 26 '19 21:07 lrasmus

@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.

Wei-Lu avatar Jul 30 '19 23:07 Wei-Lu

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.

lrasmus avatar Aug 01 '19 17:08 lrasmus

@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 avatar Aug 04 '19 04:08 lrasmus

@lrasmus Actually, it does not work after I added engine.AutoPrint = true;

I notice that I had print function around attributes(foo).

Wei-Lu avatar Aug 08 '19 20:08 Wei-Lu

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 avatar Aug 09 '19 21:08 lrasmus

@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.

MarkFleet avatar Sep 02 '19 14:09 MarkFleet

@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 avatar Oct 21 '19 16:10 MarkFleet

@MarkFleet - thanks for providing a workaround, sorry that it's still necessary. Unfortunately this one continues to stump me as to cause & solution.

lrasmus avatar Nov 04 '19 14:11 lrasmus