Skip to content
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

Non-interactive calls to ggsave() can have irritating side effects #1326

Closed
jennybc opened this issue Sep 8, 2015 · 6 comments
Closed

Non-interactive calls to ggsave() can have irritating side effects #1326

jennybc opened this issue Sep 8, 2015 · 6 comments

Comments

@jennybc
Copy link
Member

jennybc commented Sep 8, 2015

Posting an issue sort of on behalf of @cscheid because I am so thrilled at the prospect of this getting fixed! (Please correct me if I'm mangling your problem, @cscheid.)

Calls to ggsave() that don't specify device width and height cause a graphics device to be opened and consulted for dimensions. In non-interactive settings, this can have irritating side effects, such as leaving an (empty or corrupt) Rplots.pdf file behind.

Reprex: put these commands in foo.R:

library(ggplot2)
p <- ggplot(mtcars, aes(x=cyl,y=mpg)) + geom_point()
ggsave("cars.png", p)

and run Rscript foo.R. This produces cars.png AND Rplots.pdf, at least on my Mac.

Other places people where people have vented about this: stackoverflow thread How to stop R from creating empty Rplots.pdf file when using ggsave and Rscript, ggplot2 board thread ggsave always opens a graphics window on Mac OS

@cscheid
Copy link

cscheid commented Sep 8, 2015

👍 This is exactly what's been happening with me as well. Notice the silly, overspecified (but necessary) width and height in rplot

@cscheid
Copy link

cscheid commented Sep 8, 2015

(Incidentally, thank you, @jennybc, for filing the reprex and getting this off of my todo list! :))

@jennybc
Copy link
Member Author

jennybc commented Sep 8, 2015

I may or may not have encountered this problem before 😁

@hadley
Copy link
Member

hadley commented Sep 8, 2015

Well in the dev version this produces:

Desktop : Rscript test.R 
Error: No graphics device is open. Please supply height and width
Execution halted

but I think we can do a bit better ;)

@hadley hadley closed this as completed in 5fdb48a Sep 8, 2015
@jennybc
Copy link
Member Author

jennybc commented Sep 9, 2015

Here's a pretty funny GitHub search. Sure there are lots of false positives but I still think the ggplot2 world will rejoice.

@cscheid
Copy link

cscheid commented Sep 9, 2015

@jennybc that's a brilliant use of GitHub search, you're blowing my mind here.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants