1

Trying to use the awesome gganimate package in R, but was having trouble getting my animation to run. Reverted to trying to run the base example but couldn't get it to link up with ImageMagick.

Input:

library(gapminder)    
b =  ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year))+ geom_point() +scale_x_log10()
gg_animate(b)

And the output:

I cannot find ImageMagick with convert = "convert"
Error in file(file, "rb") : cannot open the connection
In addition: Warning messages:
1: running command 'C:\windows\system32\cmd.exe /c convert --version' had status 4 
2: In find_magic() : ImageMagick not installed yet!
3: In im.convert(img.files, output = movie.name, convert = convert,  :
Please install ImageMagick first or put its bin path into the system PATH variable
4: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="filed42411bd2b88.gif": The system cannot find the file specified

From the research I have done it seems that the issue has something to do with declaring convert.exe and the windows path, I'm just not sure what to fix to get this code to work.

I have installed ImageMagick-7.0.2-Q16 for Windows (I am running Windows 7).

What am I missing?

989
  • 12,579
  • 5
  • 31
  • 53
Randerson
  • 13
  • 4

1 Answers1

0

You don't need to declare convert.exe; Windows has a native cli tool with the same name to convert a FAT partition into an NTFS partition, not what you want.

(NB: I forget to which directory IM installs itself in windows, so please verify the path I provide before blindly using this code.)

If this is a one-time thing, you can make it available with something like:

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

If you want a more permanent solution, you have two options:

  1. Save the above code in a .Rprofile file, either in your home directory (affects all of your future R sessions) or in the directory of your R project needing this tool. (You either need to also run this code on the console or restart the R session for the change to be noticed in your code.)

  2. Add it to the windows path. There are lots of places to find help with this, including https://stackoverflow.com/a/28545224/3358272.

Edit: it came to my attention that the windows install no longer provides the convenience applications (e.g., convert.exe, mogrify.exe) that the unixy install does. (I'm using IM on windows installed via msys2, so I guess it's preferring the unixy-method ... I should have known.) So that suggests a third option:

  1. Since gapminder is using gganimate which is calling animation::im.convert, its source says you can specify the command executable via something like ani.options(convert = shQuote('c:/program files/imagemagick/magick.exe')).
Community
  • 1
  • 1
r2evans
  • 141,215
  • 6
  • 77
  • 149