问题
I'm trying to learn how to get a pretty animate graphic using R and gganimate, and I encounter some issue. When I try to animate my graphics, R seems to edit few PNG files, but then fail to render them. Here is an example of the code I use (tidyverse, gganimate, and gifski were loaded first):
p <- ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_point()
p + transition_states(Species)
R run the first line without issue. When it comes to the second line, console prints "rendering ----> etc.", with a countdown for a few seconds. Once it's over, it prints a lots of lines, which seems to describe the animated object (a list of PNG files, a list of states, etc.). I am guessing that's normal.
Finally, and it seems to me it is the issue, R give me a warning message:
file_renderer failed to copy frames to the destination directory
And of course, I got no animation.
I saw other subjects about this, saying maybe it is a permission issue, but I am not good enough to understand what to do. I reproduced the issue on two machines, one on Ubuntu, the other on Windows.
回答1:
first, install the gifski
package and type the code below. I have added another line. notice how +transition_states(Species)
is part of the first line to make one p
p <- ggplot(iris, aes(Sepal.Length, Petal.Length)) +
geom_point()+
transition_states(Species)
animate(p, renderer = gifski_renderer())
回答2:
I really do not get why, but the problem have been solved by itself. On both computers, and both OS, the same code is now working. I didn't change anything, so can't tell what is the reason, and it's very weird because the two machines have nothing in common. Yet, they both couldn't create an animation two days ago, and they both can now.
Conclusion : if anyone have the same issue, maybe just retry a bit later ?
Conclusion 2: maybe I am just stupid, but I could use an explanation to know why then :)
回答3:
Deleting any previously created images from the directory solved the problem for me. You can do this manually (select those images, then delete them) or using file.remove()
from within R
回答4:
You did not have read, write and execute (full access) to the location your program is saving the animate objects. Hence it cannot render. @Amanyiraho suggested to install gifski
package so that gifski_renderer()
can be used. After some reboot or updates you may have gotten full access to that location, and your program started working without any modifications.
来源:https://stackoverflow.com/questions/60259080/fail-to-render-an-animation