Skip to content

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

Closed

Description

@jennybc

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

Activity

  1. cscheid commented on Sep 8, 2015

    @cscheid

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

  2. cscheid commented on Sep 8, 2015

    @cscheid

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

  3. jennybc commented on Sep 8, 2015

    @jennybc
    MemberAuthor

    I may or may not have encountered this problem before 😁

  4. hadley commented on Sep 8, 2015

    @hadley
    Member

    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 ;)

  5. jennybc commented on Sep 9, 2015

    @jennybc
    MemberAuthor

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

  6. cscheid commented on Sep 9, 2015

    @cscheid

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

  7. locked as resolved and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions