首页 > 解决方案 > R 不执行命令行

问题描述

我正在尝试通过 R 代码执行命令行(帖子末尾的整个脚本)

system('"C:\\Program Files\\ImageMagick-7.0.8-Q16\\convert.exe" -delay 20 -loop 0 *.png julia.gif')

当然,我下载并安装了ImageMagick并验证C:\Program Files\ImageMagick-7.0.8-Q16存在于我的机器上

期望的结果是从输出(35 个 .png 文件,GitHub 上的副本)创建下面的动画。

语法看起来正确,我忽略了什么?

在此处输入图像描述

R 代码(灵感来自Fronkonstin 博客

library(ggplot2)
library(dplyr)
library(RColorBrewer)
setwd("C:/JuliaSet")
dir.create("output")
setwd("output")
f = function(z,c) exp(z^3)+c
# Grid of complex
z0 <- outer(seq(-2, 2, length.out = 1200),1i*seq(-2, 2, length.out = 1200),'+') %>% c()
opt <-  theme(legend.position="none",
              panel.background = element_rect(fill="white"),
              plot.margin=grid::unit(c(1,1,0,0), "mm"),
              panel.grid=element_blank(),
              axis.ticks=element_blank(),
              axis.title=element_blank(),
              axis.text=element_blank())
for (i in 1:35)
{
  z=z0
  # i iterations of f(z)
  for (k in 1:i) {
    z <- f(z, c=-0.621) 
    df=data.frame(x=Re(z0),
    y=Im(z0),
    z=as.vector(exp(-Mod(z)))) %>% na.omit() 
 }
  p=ggplot(df, aes(x=x, y=y, color=z)) + 
    geom_tile() + 
    scale_x_continuous(expand=c(0,0))+
    scale_y_continuous(expand=c(0,0))+
    scale_colour_gradientn(colours=brewer.pal(8, "Paired")) + opt
  ggsave(plot=p, file=paste0("plot", stringr::str_pad(i, 4, pad = "0"),".png"), width = 1.2, height = 1.2)
}
# Place the exact path where ImageMagick is installed
system('"C:\\Program Files\\ImageMagick-7.0.8-Q16\\convert.exe" -delay 20 -loop 0 *.png julia.gif')
# cleaning up
#file.remove(list.files(pattern=".png"))

标签: rcommand-lineexe

解决方案


推荐阅读