转换R动画包中未使用的路径

时间:2015-06-18 05:54:52

标签: r animation filepath

我今天开始使用animation包,并安装了ImageMagick版本6.9.1。我在Windows 7 64位环境中RStudio工作,R版本3.1.3和animation版本2.3。

我在尝试将convert.exe路径传递给R时遇到问题。我还不知道这段代码是否有效,因为我无法正确解释文件路径。 Program files中文件路径中的空格似乎导致问题,我无法解决如何解决问题。我在Windows中检查了基于this answer的路径信息,并且正确的路径在那里。

对于下面的所有示例,这是我试图开始工作的动画代码,它使用基数R将三个累积概率绘制在同一个图上。

 saveGIF(
   {
   plot(HourlySplineModel2(Hours),type="l", col="red", xlab="Hour periods", ylab="Cumulative Prob Incubation Duration")
   lines(HourlySplineModel(Hours), col="blue")
   lines(HourlySplineModel3(Hours), col="black")
   },
 movie.name = "test.gif",
 interval = 0.2,
 ani.width = 300, 
 ani.height = 300,
 outdir = "C:/Users/files"
 )

尝试使用this answer中的代码:

 path.to.convert <- paste0(shortPathName("C:\\Program Files\\ImageMagick-6.9.1-Q16\\"), "convert.exe")
 ani.options(convert=path.to.convert)

我收到此错误:

 Executing: 
 "C:\PROGRA~1\IMAGEM~1.1-Q\convert.exe" -loop 0 -delay 20 Rplot1.png "test.gif"
 'C:\PROGRA~1\IMAGEM~1.1-Q\convert.exe" -loop 0  -delay 20 Rplot1.png "test.gif' is not recognized as an internal or external command,
 operable program or batch file.
 Output at: test.gif
[1] FALSE
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c "C:\PROGRA~1\IMAGEM~1.1-Q\convert.exe" -loop 0  -delay 20 Rplot1.png "test.gif"' had status 1 
2: In cmd.fun(convert) :
  '"C:\PROGRA~1\IMAGEM~1.1-Q\convert.exe" -loop 0  -delay 20 Rplot1.png "test.gif"' execution failed with error code 1

关联的路径值是(来自ani.options()):

 $outdir
 [1] "C:/Users/files"

 $convert
 [1] "C:\\PROGRA~1\\IMAGEM~1.1-Q\\convert.exe"

我也试过this answer

 ani.options(convert = shQuote("C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe"))

我在控制台中得到了这个错误输出:

 Executing: 
 "\"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe\"" -loop 0 -delay 20 Rplot1.png "test.gif"
 The filename, directory name, or volume label syntax is incorrect.
 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-6.9.1-Q16/convert.exe\"" --version' had status 1 
 2: running command 'C:\Windows\system32\cmd.exe /c "\"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe\"" -loop 0  -delay 20 Rplot1.png "test.gif"' had status 1 
 3: In cmd.fun(convert) :
 '"\"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe\"" -loop 0  -delay 20 Rplot1.png "test.gif"' execution failed with error code 1
 4: running command '"\"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe\"" -loop 0  -delay 20 Rplot1.png "test.gif"' had status 127 

关联的路径值是(来自ani.options()):

 $outdir
 [1] "C:/Users/files"

 $convert
 [1] "\"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe\""

以为我可能会变得太复杂,我也尝试过(单引号,也有双引号,以防万一:

 ani.options(convert = 'C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe')

重新创建相同的早期错误输出:

 Executing: 
 "C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe" -loop 0 -delay 20 Rplot1.png "test.gif"
 'C:/Program' is not recognized as an internal or external command,
 operable program or batch file.
 Output at: test.gif
 [1] FALSE
 Warning messages:
 1: running command 'C:\Windows\system32\cmd.exe /c "C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe" -loop 0  -delay 20 Rplot1.png "test.gif"' had status 1 
 2: In cmd.fun(convert) :
 '"C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe" -loop 0  -delay 20 Rplot1.png "test.gif"' execution failed with error code 1

,创建的目录是:

 $outdir
 [1] "C:/Users/files"

 $convert
 [1] "C:/Program Files/ImageMagick-6.9.1-Q16/convert.exe"

0 个答案:

没有答案