R GIF animation with ImageMagick

2019-06-25 11:58发布

问题:

I've googled for over an hour now and tried everything I found on that topic. I am trying to animate a plot in R with the help of the animation package:

library(animation)
saveGIF({
for(i in 1:10) {
    plot(x=rnorm(10),y=rnorm(10))
}
})

This produces the following error:

Executing: 
"convert.exe" -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png     Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png
"animation.gif"
Der Befehl "convert.exe" -loop 0  -delay 100 Rplot1.png Rplot2.png     Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Unzul„ssiger Parameter - 0
an error occurred in the conversion... see Notes in ?im.convert
[1] FALSE
Warning messages:
1: running command 'C:\WINDOWS\system32\cmd.exe /c "convert.exe" -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif"' had status 1 
2: In cmd.fun(convert) :
'"convert.exe" -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif"' execution failed with error code 1 
3: running command '"convert.exe" -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif"' had status 4 

I already checked the system path variable

Sys.getenv('PATH')
"C:/Program Files/R\\R-3.0.2\\bin\\x64;C:\\Program Files (x86)\\ImageMagick-6.9.0-Q16;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;F:\\Program Files (x86)\\MATLAB\\R2014a\\bin;C:\\Program Files (x86)\\MiKTeX 2.9\\miktex\\bin\\;C:\\Users\\Maddin\\AppData\\Local\\Pandoc\\"

I tried both the 64-bit and 32-bit versions of ImageMagick. I tried setting the ani.options convert attribute manually. Nothing helped. When I open the command line tool and test if convert.exe works, everythings fine. But from inside R I just dont get it to work -.-

Fun fact: on my MacBook its working flawless.....

Here is my sessionInfo():

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_1.0.0 animation_2.3 dplyr_0.2     magrittr_1.5 

loaded via a namespace (and not attached):
[1] assertthat_0.1   colorspace_1.2-4 digest_0.6.4     gtable_0.1.2     lattice_0.20-29  lmtest_0.9-33    MASS_7.3-33      munsell_0.4.2   parallel_3.0.2  
[10] plyr_1.8.1       proto_0.3-10     Rcpp_0.11.3      reshape2_1.4     sandwich_2.3-2   scales_0.2.4     stringr_0.6.2    tools_3.0.2      urca_1.2-8      
[19] vars_1.5-2       zoo_1.7-11      

Anyone an idea what else I could try?

Martin

回答1:

Recently, we fix a bug in im.convert() function, you can check issue #71 . I tested the new im.convert() function on my laptop( Windows Vista with Revolution R). It seems that saveGIF() function works well after updating to the development version animation package. Would anyone can help me to test if you can save GIF successfully with the development version?

Here are some testing code.

install.packages("devtools")
library(devtools)

dev_mode(on=T)

install.packages('animation', repos = 'http://yihui.name/xran')
library(animation)
saveGIF({
    for (i in 1:10) plot(runif(10), ylim = 0:1)
})

dev_mode(on=F)


回答2:

I've been through this error. I don't have a flawless solution to this, but you can try install the development version of the package 'animation' and it doesn't return errors any more.

library(devtools)
install_github("yihui/animation")