我正在尝试在 R 中制作 GIF 动画。我有一组矩阵,我希望将其转换为 GIF 动画。我的策略灵感来自这个例子:
http://ryouready.wordpress.com/2010/11/21/animate-gif-images-in-r-imagemagick/
以下代码在 R 中使用“png”函数生成 11 个 PNG 图片。接下来,它调用外部 ImageMagick 程序“convert”来编译 GIF 动画。
dir.create("examples")
setwd("examples")
# Animated countdown from 10 to "GO!".
png(file="example%02d.png", width=200, height=200)
for (i in c(10:1, "G0!")){
plot.new()
text(.5, .5, i, cex = 6)
}
dev.off()
# convert the .png files to one .gif file using ImageMagick.
system("convert -delay 80 *.png example_1.gif")
#shell("convert -delay 80 *.png example_1.gif")
问题是 R 似乎没有找到作为 ImageMagick 一部分并安装在 C 驱动器上的 exe 文件“convert”(C:\Program Files\ImageMagick-6.8.5-Q16)。在对我之前链接到的网站的评论中,建议 Windows 用户使用“shell”而不是“system”来运行外部程序,但两者都不起作用。错误信息是
Invalid parameter - 80
Warning message:
running command 'convert -delay 80 *.png example_1.gif' had status 4
我已尝试更改系统属性中的 Windows PATH 环境变量,如this answer中所建议的那样,但 PATH 变量已在我的系统上正确定义。我还尝试指定 convert.exe 文件的整个字符串,但也没有运气......
我怎样才能让 ImageMagick 通过 R 运行?
规格:Windows 7 Servicepack 1、R 3.0.0
提前致谢...