r - linux 命令行中的 knitr

标签 r linux shell knitr

我知道下面的代码可以在 linux 的终端中将 Rnw 文件编织成 pdf,但是行太多了,而对于 Rstudio 来说,这样做只需要单击一下。有人可以提供一个 linux shell 函数来将文件名作为变量处理吗?例如,我尝试使用 $1,但是 Rscript 和 Rnw 文件名有 ""和 '',shell 无法识别 $1 是什么。

Rscript -e "library(knitr); knit('my_sweave_file.Rnw')"
    pdflatex my_sweave_file.tex

最佳答案

你可以使用这样的东西。另存为文件并确保它可以运行(即使用 chmod +x nameofscript)。

#!/bin/bash

# Set the first argument as variable file    
file=$1

filename=$(basename "$file")
extension="${filename##*.}"
filename="${filename%.*}"

Rscript -e "library(knitr); knit('$file')" ; pdflatex $filename.tex

关于r - linux 命令行中的 knitr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45370177/

相关文章:

r - 添加多行绘图,无需 ggplot

R 方差膨胀因子 - 警告 : No function found corresponding to methods exports from ‘SparseM’ for: ‘coerce’

linux - 在 unix 中并行运行多个命令

linux - ls -d 命令在 linux 终端中代表什么?

r - gsub 返回表达式的所有匹配项,而不仅仅是最后一个匹配项

r - 如何合并2个数据框以填充R中的缺失值?

c - ePoll 不接受一些客户

c++ - C/C++多进程访问同一个变量的方法

Linux 64 位 BAR 编程

linux - 在 Unix 中合并来自多个文件的列