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

ggsave creating new directories when saving jpg/tiff/png devices #5489

Closed
tjebo opened this issue Oct 20, 2023 · 2 comments · Fixed by #5492
Closed

ggsave creating new directories when saving jpg/tiff/png devices #5489

tjebo opened this issue Oct 20, 2023 · 2 comments · Fixed by #5492

Comments

@tjebo
Copy link

tjebo commented Oct 20, 2023

Related feature request #3021 was closed as not desired. ggsave however, indeed creates new directories when saving.

This happens only with png, tiff, and jpeg devices

## all of the below would create a directory that does not exist
ggsave("test/test.png", plot = ggplot())
ggsave("test/test.jpg", plot = ggplot())
ggsave("test/test.tiff", plot = ggplot())

Does not happen with eps, ps, pdf, bmp, svg (error message).

## All of the below give an error message 
ggsave("test/test.eps", plot = ggplot())
ggsave("test/test.ps", plot = ggplot())
ggsave("test/test.bmp", plot = ggplot())
ggsave("test/test.svg", plot = ggplot())
ggsave("test/test.pdf", plot = ggplot())

P.S. behaviour originally described in this stack overflow thread

@tjebo tjebo changed the title ggsave creating new directories when saving ggsave creating new directories when saving jpg/tiff/png devices Oct 20, 2023
@teunbrand
Copy link
Collaborator

Curious, I suppose that graphics devices control whether they're allowed to create directories.
For consistency reasons ggplot2 might take that control into its own hands, but I'm unsure what the default behaviour should be.

@bk1n
Copy link

bk1n commented Oct 23, 2023

I believe this is new behaviour? Previously ggsave would throw errors if the path did not exist, but now it is creating it's own directories.

I would personally say the default behaviour should be to throw errors, unless specified otherwise, as this could (and has in my case!) wreaked havoc on my project directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants