使用ImageMagick制作R GIF动画

4

我已经谷歌了一个多小时,尝试了所有与此主题相关的内容。我正在尝试使用动画包在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\\"

我尝试过ImageMagick的64位和32位版本。我尝试手动设置ani.options转换属性,但没有效果。当我打开命令行工具并测试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      

请问还有什么其他的尝试方法吗?

Martin

2个回答

3
我曾经遇到过这个错误。我没有完美的解决方案,但你可以尝试安装包的开发版本“animation”,这样就不会再出现错误了。
library(devtools)
install_github("yihui/animation")

1

最近,我们修复了 im.convert() 函数中的一个错误,您可以查看 问题 #71

我在我的笔记本电脑上(Windows Vista with Revolution R)测试了新的 im.convert() 函数。更新到开发版本的 animation 包后,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)

我想下载那个动画版本,但是无法下载。在安装包时出现警告: “yihui/animation”包不可用(适用于R版本3.2.2) curl: (22) 请求的URL返回错误:404 Not Found - Martin Schmelzer
我在这里上传了软件包的开发版本,只需单击raw按钮即可下载。然后尝试安装本地软件包,library("devtools"); install_local("animation_2.4.1.tar.gz") - Lijia Yu
谢谢。我会研究一下 :) - Martin Schmelzer
我在使用R 3.2.2ImageMagick 6.9.2-8 Q16 x86_64 2015-12-06时,在OS X 10.11.1上没有遇到任何问题。我尝试了不同的动画效果,使用了不同的绘图系统和文件格式。 - Martin Schmelzer
感谢您的测试和反馈! - Lijia Yu
这个功能还只在开发版本中吗? - MichaelChirico

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接