0

I ran into a very weird problem: my R code for generating a plot only works if I type it into the console but not when I ran it inside the script (with Ctrl+Enter command)... It's the same problem with all plots (regular plots or ggplots). Also I tried it on two different computers and the same thing happened. Anyone have any idea why this is happening?

One possible reason: I installed the newest version of Rstudio on both computers so it might be an issue with the version. The exact same code worked before on an older version of rstudio...Could this be it? If so, how can I fix it?

I think I figured out what the problem was: the setting in the new version of Rstudio has a default option of outputting the plots inside the Rmarkdown script (at the very end of the script). And that's why I wasn't seeing them. You could change the setting such that it outputs in the console.

cw.01
  • 1
  • 3
  • Have you tried the solutions to [this question](http://stackoverflow.com/questions/26643852/ggplot-plots-in-scripts-do-not-display-in-rstudio?rq=1)? – Joe Nov 27 '16 at 10:02
  • Yes I did. Same thing: print didn't work and when I assign an object to the plot, I can only call it from the console--calling it in the script didn't work... – cw.01 Nov 27 '16 at 17:20
  • Works for me at version 1.0.44. What kind of plots are you making? – Roman Luštrik Nov 27 '16 at 20:51

3 Answers3

0

Try dev.off() to reset the graphics device.

This helps with a lot of weird graphics behaviour.

TinaW
  • 989
  • 1
  • 18
  • 28
  • Hi thanks for your answer. But I tried that and it didn't work...On either computer... – cw.01 Nov 27 '16 at 08:02
  • Downgrade the version then if the last one works. Try again in a few days when this might have been spotted and fixed. https://support.rstudio.com/hc/en-us/articles/206569407-Older-Versions-of-RStudio – TinaW Nov 27 '16 at 08:04
0

Probably too late for the original poster... However, I just ran into the same problem after installing an R update. The way I fixed it was to go to preferences, R markdown, and turn off "show inline output". For me, it was just coming out at the bottom of the chunk instead of in the plot window like I wanted. Hope that helps someone!

Ashish
  • 178
  • 1
  • 11
0

I just ran into this problem. I mistakenly put my plot() command inside the r markdown setup chunk. I moved it to its own code chunk and it ran as expected.

Joe Moran
  • 1
  • 1