R {animation} package [saveGIF] - want to use magi

2019-08-06 15:12发布

问题:

I want to make a GIF animation file from a series of R plots. I installed ImageMagick and "animation" package to do this.

I want to use saveGIF function, but when I uses the function, it tries to use convert.exe in ImageMagick and gives an error. It looks like the current version of ImageMagick uses magick.exe instead of convert.exe (convert.exe does not exist).

I was able to make a GIF animation directly from ImageMagick using magick.exe without using the animation package. But it is more convenient for me if I can make saveGIF to use magick.exe instead of convert.exe. I want to know how to do it.

Installing an older version of ImageMagick that still uses convert.exe would solve the problem, but this is not an answer I am looking for.

UPDATE

I tried ani.options suggested by Josh O'Brien. Below is what I got. Not sure what the problem is...

> ani.options(convert = 'C:/Program Files/ImageMagick-7.0.5-Q16/magick.exe')
> 
> saveGIF(
+ for(i in 1:10){
+ plot(i,1,xlim=c(0,11))
+ }
+ )
Executing: 
"C:/Program Files/ImageMagick-7.0.5-Q16/magick.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""
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
an error occurred in the conversion... see Notes in ?im.convert
[1] FALSE
Warning messages:
1: running command 'C:\WINDOWS\system32\cmd.exe /c "C:/Program Files/ImageMagick-7.0.5-Q16/magick.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) :
  '"C:/Program Files/ImageMagick-7.0.5-Q16/magick.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 '"C:/Program Files/ImageMagick-7.0.5-Q16/magick.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 127 

回答1:

Josh O'Brien's answer worked. "Program Files" had to be changed to "PROGRA~1".

ani.options(convert = 'C:/PROGRA~1/ImageMagick-7.0.5-Q16/magick.exe')

saveGIF(
for(i in 1:10){
plot(i,1,xlim=c(0,11))
}
)


标签: r animation