Skip to content

Error using ggsave with purrr::map; Working in release 3.3.3, but not >= 3.3.4 #5114

Closed as not planned
@phdjsep

Description

@phdjsep

I'm using purrr::map and ggsave to write out multiple plots to disk and the following code works in ggplot2 release = 3.3.3, but not >= 3.3.4. Can't pinpoint what's changed that prevents this from working.

ggplot2 v3.3.3 (working)

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(purrr)

# Working with ggplot 3.3.3, but not 3.3.4
diamonds %>%
  group_by(cut) %>%
  group_split() %>%
  purrr::map(~ ggsave(filename = paste("diamonds", .x$cut, .x$color, sep = "_"),
                      plot = ggplot(.x, aes(x = carat, y = depth)) +
                        geom_point(),
                      device = 'jpeg',
                      path = "~/Desktop/empty/"))
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> [[1]]
#> NULL
#> 
#> [[2]]
#> NULL
#> 
#> [[3]]
#> NULL
#> 
#> [[4]]
#> NULL
#> 
#> [[5]]
#> NULL

ggplot2 v3.3.4 (broken)

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(purrr)

# Working with ggplot 3.3.3, but not 3.3.4
diamonds %>%
  group_by(cut) %>%
  group_split() %>%
  purrr::map(~ ggsave(filename = paste("diamonds", .x$cut, .x$color, sep = "_"),
                      plot = ggplot(.x, aes(x = carat, y = depth)) +
                        geom_point(),
                      device = 'jpeg',
                      path = "~/Desktop/empty/"))
#> Saving 7 x 5 in image
#> Error in if (!dir.exists(dir)) {: the condition has length > 1

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