将R链接到ImageMagick

将R链接到ImageMagick,r,ggplot2,imagemagick,R,Ggplot2,Imagemagick,试图在R中使用awesomegganimate软件包,但在运行动画时遇到问题。已还原为尝试运行基本示例,但无法使其与ImageMagick链接 输入: library(gapminder) b = ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year))+ geom_point() +scale_x_log10() gg_animate(b) 以及输出: I cann

试图在R中使用awesome
gganimate
软件包,但在运行动画时遇到问题。已还原为尝试运行基本示例,但无法使其与
ImageMagick
链接

输入:

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

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
从我所做的研究来看,这个问题似乎与声明convert.exe和windows路径有关,我只是不确定要修复什么才能使代码正常工作

我已安装ImageMagick-7.0.2-Q16 for Windows(我正在运行Windows 7)

我缺少什么?

您不需要声明
convert.exe
;Windows有一个本机cli工具,该工具的名称与您的相同,而不是您想要的

(注意:我忘了IM在windows中安装到哪个目录,所以请在盲目使用此代码之前验证我提供的路径。)

如果这是一次性的,您可以通过以下方式提供:

Sys.setenv(PATH = paste("c:/Program Files/ImageMagick/bin",
                        Sys.getenv("PATH"), sep = ";"))
如果您想要更持久的解决方案,您有两种选择:

  • 将上述代码保存在
    .Rprofile
    文件中,或者保存在您的主目录(影响您未来的所有R会话)中,或者保存在需要此工具的R项目目录中。(您还需要在控制台上运行此代码,或者重新启动R会话,以便在代码中注意到更改。)

  • 将其添加到windows路径。有很多地方可以找到帮助,包括

  • 编辑:windows安装不再提供unixy安装所提供的方便应用程序(例如,
    convert.exe
    mogrify.exe
    )。(我在通过msys2安装的windows上使用IM,所以我想它更喜欢unixy方法……我应该知道。)因此,这建议了第三种选择:

  • 由于
    gapminder
    正在使用调用
    animation::im.convert
    ,因此表示可以通过类似
    ani.options(convert=shQuote('c:/program files/imagemagick/magick.exe')的方式指定可执行命令。
  • 您不需要声明
    convert.exe
    ;Windows有一个本机cli工具,该工具的名称与您的相同,而不是您想要的

    (注意:我忘了IM在windows中安装到哪个目录,所以请在盲目使用此代码之前验证我提供的路径。)

    如果这是一次性的,您可以通过以下方式提供:

    Sys.setenv(PATH = paste("c:/Program Files/ImageMagick/bin",
                            Sys.getenv("PATH"), sep = ";"))
    
    如果您想要更持久的解决方案,您有两种选择:

  • 将上述代码保存在
    .Rprofile
    文件中,或者保存在您的主目录(影响您未来的所有R会话)中,或者保存在需要此工具的R项目目录中。(您还需要在控制台上运行此代码,或者重新启动R会话,以便在代码中注意到更改。)

  • 将其添加到windows路径。有很多地方可以找到帮助,包括

  • 编辑:windows安装不再提供unixy安装所提供的方便应用程序(例如,
    convert.exe
    mogrify.exe
    )。(我在通过msys2安装的windows上使用IM,所以我想它更喜欢unixy方法……我应该知道。)因此,这建议了第三种选择:

  • 由于
    gapminder
    正在使用调用
    animation::im.convert
    ,因此表示可以通过类似
    ani.options(convert=shQuote('c:/program files/imagemagick/magick.exe')的方式指定可执行命令。

  • @Randerson,看我的编辑,我认为这可能是解决你问题的更好的答案。选项3就是解决这个问题的方法。感谢@r2evans的帮助@Randerson,看我的编辑,我认为这可能是解决你问题的更好的答案。选项3就是解决这个问题的方法。感谢@r2evans的帮助!