0

I am trying to produce a GIF file for my maps in R using gganimate but errors show up.

devtools::install_github("dgrtwo/gganimate")

library(ggplot2)
data(sp6, package = 'aqp')
p <- ggplot(sp6, aes(x = pH, frame = hz)) +geom_density() 
library(gganimate)

Error in fetch(key) : lazy-load database 'C:/R/R-3.4.2/library/gganimate/help/gganimate.rdb' is corrupt

(I think this can be fixed by restart R session? Anyway, the real problem below ...)

gganimate(p)

Executing: "C:\ImageMagick-7.0.7-Q16\convert.exe -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png "file148c3014687f.gif"" 'C:\ImageMagick-7.0.7-Q16\convert.exe' 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 Error in file(file, "rb") : cannot open the connection In addition: Warning messages: 1: running command 'C:\WINDOWS\system32\cmd.exe /c "C:\ImageMagick-7.0.7-Q16\convert.exe" --version' had status 1 2: running command 'C:\WINDOWS\system32\cmd.exe /c "C:\ImageMagick-7.0.7-Q16\convert.exe -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png "file148c3014687f.gif""' had status 1 3: In cmd.fun(convert) : '"C:\ImageMagick-7.0.7-Q16\convert.exe -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png "file148c3014687f.gif""' execution failed with error code 1 4: running command '"C:\ImageMagick-7.0.7-Q16\convert.exe -loop 0 -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png "file148c3014687f.gif""' had status 127 5: In file(file, "rb") : cannot open file 'C:\Users\gjiang\AppData\Local\Temp\RtmpA95rFH/gganimate\file148c3014687f.gif': No such file or directory

Is there a way to fix this?

P.S

After installing the software ImageMagick 7.0.7, I used p <- animate(ras.stack) in the raster package and then used saveGIF(p) in the animation package, but still getting

'C:\ImageMagick-7.0.7-Q16\convert.exe' is not recognized as an internal or external command, operable program or batch file.

  • ImageMagick is a stand alone application and not an R package. The animate package uses it to build gifs. You need go to the relevant website, download and install the software. – Jeffrey Evans Oct 24 '17 at 21:16
  • I downloaded and installed ImageMagick 7.0.7, then reinstalled gganimate in R again, but still getting error: 'C:\ImageMagick-7.0.7-Q16\convert.exe' is not recognized as an internal or external command, operable program or batch file. Does ImageMagick have to be installed under a certain path? @JeffreyEvans – Gorden Jiang Oct 24 '17 at 22:20
1

It looks like this is a documented issue in gganimate. The animate packages deals with some of the known issues but gganimate is a bit behind on addressing changes in ImageMagick. Two potential workarounds are:

Running an installation directly in R using installr.

library(installr)
install.ImageMagick()

Or, setting a windows environment variable from R.

Sys.setenv(PATH = paste("C:/Program Files/ImageMagick/bin",
Sys.getenv("PATH"), sep = ";"))

Although, it looks like the new version of ImageMagick does not distribute the "convert.exe" executable. The portable install does, however, contain the "convert.exe". All you have to do is create an ImageMagick directory and uncompress the zip file to it. The "convert.exe" executable is then contained in root and not bin, which becomes relevant if you have to explicitly set the path. If you put the directory under "C:/" the path would look like this:

Sys.setenv(PATH = paste("C:/ImageMagick", Sys.getenv("PATH"), sep = ";"))

You can grab the portable install at: ftp://ftp.imagemagick.org/pub/ImageMagick/binaries/ImageMagick-7.0.7-8-portable-Q16-x64.zip

  • install.ImageMagick(URL = "http://www.imagemagick.org/script/binary-releases.php") shows Error in file(con, "r") : cannot open the connection. The portable install works perfect. Thanks a lot @Jeffrey Evans – Gorden Jiang Oct 24 '17 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.