Skip to content

ggsave creates superflous, misnamed additional directory when saving to a directory containing a % character #6857

@stephan-hutter

Description

@stephan-hutter

Tested on Windows 11 and Amazon Linux 2023

When saving a plot to a directory containing a % character via ggsave one has to use %% in order for the character to be read as a single %.

However, when you do this ggsave will prompt that it cannot find the directory and ask to create a directory (or automatically create the directory if create.dir = TRUE).

It will then proceed to create a directory where all %% are interpreted literally as two % characters, but continue to store the file in the original requested directory, leaving the newly created directory empty.

Obviously, this second directory should never be created.

Reprex:

dir.create("a%b")
ggplot2::ggsave("a%%b/test.png", 
                ggplot2::ggplot(cars) + ggplot2::geom_bar(ggplot2::aes(x = speed)), 
                create.dir = TRUE)
#> ✔ Created directory: 'a%%b'.
#> Saving 7 x 5 in image

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