使用 ImageMagick 的 R GIF 动画

R GIF animation with ImageMagick

我已经用谷歌搜索了一个多小时,并尝试了我在该主题上找到的所有内容。 我正在尝试在动画包的帮助下为 R 中的情节制作动画:

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

这会产生以下错误:

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 

我已经检查了系统路径变量

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\"

我尝试了 64 位和 32 位版本的 ImageMagick。 我尝试手动设置 ani.options convert 属性。没有任何帮助。 当我打开命令行工具并测试 convert.exe 是否有效时,一切正常。但是从 R 里面我就是不让它工作 -.-

有趣的事实:在我的 MacBook 上它运行完美......

这是我的 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      

有人知道我还能尝试什么吗?

马丁

我遇到过这个错误。我对此没有完美的解决方案,但您可以尝试安装软件包的开发版本 'animation' 并且它不再 return 错误。

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

最近修复了im.convert()函数的一个bug,大家可以查看issue #71。 我在笔记本电脑上测试了新的 im.convert() 函数(Windows Vista with Revolution R)。更新到开发版动画包后,saveGIF()函数似乎可以正常使用。 谁能帮我测试下开发版能不能保存GIF成功?

这是一些测试代码。

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)