首页 > 解决方案 > 从命令提示符在 .Rmd 上运行 .Rexec

问题描述

所以我按照这个博客创建了一个名为 r2jekyll 的可执行文件

不幸的是,我在 Windows 上,所以我不得不以不同的方式创建名为 r2jekyll 的 .Rexec

r2jekyll 的代码在这里:

 #!/usr/bin/env Rscript
library(knitr)

# Get the filename given as an argument in the shell.
args = commandArgs(TRUE)
filename = args[1]

# Check that it's a .Rmd file.
if(!grepl(".Rmd", filename)) {
  stop("You must specify a .Rmd file.")
}

# Knit and place in _posts.
dir = paste0("../_posts/", Sys.Date(), "-")
output = paste0(dir, sub('.Rmd', '.md', filename))
knit(filename, output)

# Copy .png files to the images directory.
fromdir = "{{ site.url }}/images"
todir = "../images"

pics = list.files(fromdir, ".png")
pics = sapply(pics, function(x) paste(fromdir, x, sep="/"))
file.copy(pics, todir)

unlink("{{ site.url }}", recursive = TRUE)

一切正常,我可以运行我的 r2jekyll rexec(感谢这个博客)它运行但没有任何反应

我已经到了在名为 first_test.Rmd 的文件上运行 r2jekyll 的最后一步

我在命令提示符下运行以下代码

cd (go to directory where my r2jekyll and my first_test.Rmd are sitting)

然后

r2jekyll.rexec first_test.Rmd (the blog author used this code, he is on a mac)

我收到以下错误

错误:您必须指定一个 .Rmd 文件。执行停止

所以我的问题是:我如何让我的 r2jekyll.Rexec 对 first_test.Rmd 做它的事情

标签: rcommandr-markdown

解决方案


推荐阅读