-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggsave is not working when executed via Rscript. #2752
Comments
Sometimes I find that the pdf reader (e.g. Adobe reader) prevents other programs from changing the file; presumably some locking mechanism. Maybe try another filename. |
hi baptiste, I was actually outputing a PNG file. I search all over stack/github for the issue. Tried many work arounds like setting image size, output type etc. but nothing worked. I uninstalled the new version of ggplot and reinstalled the old version and the problem was solved, so I am pretty sure it was something in the new update. There were a few changes made to ggsave function recently, perhaps that is why it doesnt work when running from Rscript. As I said, it works fine when you execute in R or Rstudio, just not from Rscript.exe. That error message was sent I think from the following documentation., https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/pdf.html |
Can you please provide a minimal reproducible example? From what you have provided in your issue description it's impossible to guess what's going on. |
clauswilke, unfortunatly I already reinstalled the old version of ggplot2 on my machine so the issue is fixed. What I can say is try running any script that creates a standard ggplot2 chart from a file, and do so running via task scheduler / Rscript.exe. That is basically what I did and still go the same error. The issue was only about saving the plot calling ggsave, ONLY from Rscript.exe I am on a windows 10 machine. Hope that helps. ` set.seed(1234) ` |
Could you run a script that contains the following one line of code and see if it triggers the error? grDevices::dev.set(1) |
Also, I assume that as a workaround, adding the following to the script should prevent the error: setwd("C:/myDirectory/") I don't run Windows, so I can't debug this directly. |
setting the directory hasnt been a problem, as long as the output file has a complete path + file name. Its probably more related to the dev.set(1). I just ran on a version of R with ggplot2 new version and with the older version, and got the same results. Old ggplot 2 worked, new ggplt didnt If I set the grDevices::dev.set(1) the file does not run via Rscript.exe, even using the old ggplot2 package. Hope that is clear. Sorry I can't be of more help. But let me me know if there is something else I can do to troubleshoot this isse the full code uused to produce the file `library(ggplot2) set.seed(1234) |
@abeeCrombie We need to be systematic about things. Please try the following two tests:
|
Actually, and one more test. What happens if you place |
@clauswilke I ran a few tests on my Windows machine with the script above (& @dpseidel 's guidance). Hopefully this can help clarify the problem discussed above: When I ran Using For both, I get the same behavior with
@dpseidel suspects that it might be something to do with looping/the task scheduler, possibly unrelated to Windows/Mac (I think she got similar results) |
Admittedly this isn't directly reproducing the creation of an .exe file and use of a task scheduler, so hopefully it's not a red herring, but I'm getting the same behaviour when testing with ggplot2 2.2.1: without |
my mistake. That simple script is working on both ggplot versions. Sorry to bother everyone. |
or magically the windows update my PC did last night solved the issue ;-) |
Great, closing this now. |
I made a PR that will likely fix this issue. It would be great if somebody could test. See here: |
I just want to confirm that @clauswilke's PR(2758) fixes a related issue I am seeing with
A simple workaround is to set an available device before calling
Not that big a deal, but having @clauswilke's fix merged to master would be preferable. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
sorry this is a bit above my pay grade but I just spent all afternoon trying to figure out why a script I run wasnt working. I loaded the new ggplot package yesterday and now all my scripts that I run via task scheduler dont execute the ggsave command.
here is the error message I got
Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : cannot open file 'Rplots.pdf' Calls: ggsave ... withVisible -> eval -> eval -> <Anonymous> -> <Anonymous> Execution halted
code works fine in Rstudio and R command but not via Rscript.exe.
I see there were some recent commits. Hopefully you guys are smarter than me to figure out why its not working
The text was updated successfully, but these errors were encountered: