gganimate parallel - 提供的文件不存在错误
gganimate parallel - Provided file does not exist error
我正在尝试使用 gganimate
进行并行处理,但是当使用 anim_save
时,我收到“提供的文件不存在”错误。它还显示“调用自:png_dim(frames1)”。错误似乎来自包中的 aaa.R
文件,并且仅在某些情况下发生。我不知道它是否相关,但我我正在使用 RStudio 和 Mac.
我正在使用来自 Github 拉取请求的 gganimate
的修改版本,如这个问题的答案中所述:. I call this new package gganimatep
. The way I did this, based on the answer, was to download the zipped file from the link in the answer, change the file name in DESCRIPTION (to gganimatep), delete the vignettes folder, and then do RStudio / Build / Install and restart
. (I am not very familiar with Github, but I noticed that the gganimate parallel page (https://github.com/HenrikBengtsson/gganimate/tree/feature/parallel-animate) 说 This branch is 2 commits ahead, 42 commits behind thomasp85:master.
我不不知道这是否意味着我在安装的时候基本上是在安装一个老版本的gganimate
。)
第一个例子(基本代码取自https://ggplot2.tidyverse.org/reference/ggsf.html):
library(tidyverse)
library(sf)
library(gganimate)
library(future)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
set.seed(1)
nc1 <- nc %>% mutate(value = AREA, year = 1)
nc2 <- nc %>% mutate(value = AREA + runif(1, -.2, .2), year = 2)
nc3 <- nc2 %>% mutate(value = value + runif(1, -.2, .2), year = 3)
nc_new <- bind_rows(nc1, nc2, nc3)
b <- ggplot(nc_new) +
geom_sf(aes(fill = value)) +
labs(title = 'Year: {frame_time}') +
transition_time(year)
如果我们使用基础gganimate
(没有并行处理),它有效:
b
或
gganimate::anim_save("test.gif", b, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
但是如果我们使用gganimatep
进行并行处理,它就不起作用了:
library(gganimatep)
plan(multisession, workers = 7)
b
或
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", b, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
截图:
因为 b
和 anim_save
给出相同或非常相似的错误,我断定这不是 anim_save
的问题,但更有可能与 gganimatep
.
再举个例子。使用 gganimate 网站 (https://gganimate.com/) 中的示例代码,此 有效 :
library(gganimatep)
library(gganimate)
library(ggplot2)
library(gapminder)
library(future)
library(countrycode)
#devtools::install_github("rensa/ggflags")
library(ggflags)
g <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", g, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
当我做一些稍微不同的事情(将点更改为标志)时,基础 gganimate
(不是并行处理)工作:
gapminder2 <- gapminder
gapminder2$country2 <- countrycode(as.character(gapminder2$country),"country.name","iso2c")
gapminder2$country2 <- tolower(gapminder2$country2)
gapminder2$country2 <- as.character(gapminder2$country2)
g2 <- ggplot(gapminder2, aes(gdpPercap, lifeExp, size = pop, country=country2)) +
geom_flag(show.legend=FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
gganimate::anim_save("test.gif", g2, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
但是,当我切换到 gganimatep
时,它 不 工作:
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", g2, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
我收到以下错误:
如上所述,是“提供的文件不存在”错误。”和“调用自:png_dim(frames1)”。看来是来自aaa.R
文件.
在另一个实例中,它说:
Inserting image 300 at 29.90s (100%)...
Encoding to gif... done!
Warning message:
In file.create(to[okay]) :
cannot create file 'tmean_2020.gif', reason 'Read-only file system'
在另一个实例中,它说:
请注意,另一件事(不是 MWE)也不适用于 gganimatep
是:
a <- ggplot(weather2) +
geom_sf(aes(fill = temp, geometry=geometry, group=NAME)) +
scale_fill_viridis_c(name = NULL) +
theme_map() +
transition_time(as.integer(date)) +
labs(subtitle = paste('Date: {frame_time}'))
setwd("/")
plan(multisession, workers = 7)
gganimatep::anim_save("tmean_2020.gif", a, end_pause=8, width = 600, height = 400, duration=30, nframes=300)
我该怎么做才能解决这个问题?谢谢!
通过反复试验,以下似乎是问题所在:需要从 GitHub 拉取请求 (a) 构建包(如 所述)并且需要命名gganimate
以满足内部依赖性。
正确设置环境后,并行处理似乎不使用 plan(multisession, workers=7)
命令,但使用它似乎会引发错误。
(详见问题下的讨论)
我正在尝试使用 gganimate
进行并行处理,但是当使用 anim_save
时,我收到“提供的文件不存在”错误。它还显示“调用自:png_dim(frames1)”。错误似乎来自包中的 aaa.R
文件,并且仅在某些情况下发生。我不知道它是否相关,但我我正在使用 RStudio 和 Mac.
我正在使用来自 Github 拉取请求的 gganimate
的修改版本,如这个问题的答案中所述:gganimatep
. The way I did this, based on the answer, was to download the zipped file from the link in the answer, change the file name in DESCRIPTION (to gganimatep), delete the vignettes folder, and then do RStudio / Build / Install and restart
. (I am not very familiar with Github, but I noticed that the gganimate parallel page (https://github.com/HenrikBengtsson/gganimate/tree/feature/parallel-animate) 说 This branch is 2 commits ahead, 42 commits behind thomasp85:master.
我不不知道这是否意味着我在安装的时候基本上是在安装一个老版本的gganimate
。)
第一个例子(基本代码取自https://ggplot2.tidyverse.org/reference/ggsf.html):
library(tidyverse)
library(sf)
library(gganimate)
library(future)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
set.seed(1)
nc1 <- nc %>% mutate(value = AREA, year = 1)
nc2 <- nc %>% mutate(value = AREA + runif(1, -.2, .2), year = 2)
nc3 <- nc2 %>% mutate(value = value + runif(1, -.2, .2), year = 3)
nc_new <- bind_rows(nc1, nc2, nc3)
b <- ggplot(nc_new) +
geom_sf(aes(fill = value)) +
labs(title = 'Year: {frame_time}') +
transition_time(year)
如果我们使用基础gganimate
(没有并行处理),它有效:
b
或
gganimate::anim_save("test.gif", b, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
但是如果我们使用gganimatep
进行并行处理,它就不起作用了:
library(gganimatep)
plan(multisession, workers = 7)
b
或
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", b, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
截图:
因为 b
和 anim_save
给出相同或非常相似的错误,我断定这不是 anim_save
的问题,但更有可能与 gganimatep
.
再举个例子。使用 gganimate 网站 (https://gganimate.com/) 中的示例代码,此 有效 :
library(gganimatep)
library(gganimate)
library(ggplot2)
library(gapminder)
library(future)
library(countrycode)
#devtools::install_github("rensa/ggflags")
library(ggflags)
g <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", g, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
当我做一些稍微不同的事情(将点更改为标志)时,基础 gganimate
(不是并行处理)工作:
gapminder2 <- gapminder
gapminder2$country2 <- countrycode(as.character(gapminder2$country),"country.name","iso2c")
gapminder2$country2 <- tolower(gapminder2$country2)
gapminder2$country2 <- as.character(gapminder2$country2)
g2 <- ggplot(gapminder2, aes(gdpPercap, lifeExp, size = pop, country=country2)) +
geom_flag(show.legend=FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
facet_wrap(~continent) +
labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
gganimate::anim_save("test.gif", g2, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
但是,当我切换到 gganimatep
时,它 不 工作:
plan(multisession, workers = 7)
gganimatep::anim_save("test.gif", g2, end_pause=8, width = 600, height = 400, duration=5, nframes=50)
我收到以下错误:
如上所述,是“提供的文件不存在”错误。”和“调用自:png_dim(frames1)”。看来是来自aaa.R
文件.
在另一个实例中,它说:
Inserting image 300 at 29.90s (100%)...
Encoding to gif... done!
Warning message:
In file.create(to[okay]) :
cannot create file 'tmean_2020.gif', reason 'Read-only file system'
在另一个实例中,它说:
请注意,另一件事(不是 MWE)也不适用于 gganimatep
是:
a <- ggplot(weather2) +
geom_sf(aes(fill = temp, geometry=geometry, group=NAME)) +
scale_fill_viridis_c(name = NULL) +
theme_map() +
transition_time(as.integer(date)) +
labs(subtitle = paste('Date: {frame_time}'))
setwd("/")
plan(multisession, workers = 7)
gganimatep::anim_save("tmean_2020.gif", a, end_pause=8, width = 600, height = 400, duration=30, nframes=300)
我该怎么做才能解决这个问题?谢谢!
通过反复试验,以下似乎是问题所在:需要从 GitHub 拉取请求 (a) 构建包(如 gganimate
以满足内部依赖性。
正确设置环境后,并行处理似乎不使用 plan(multisession, workers=7)
命令,但使用它似乎会引发错误。
(详见问题下的讨论)