使用R脚本从命令行进行简单绘图非常方便.然而,从bash脚本运行R一点也不方便.理想可能是这样的
#!/path/to/R
...
或
#!/usr/bin/env R
...
but I haven't been able to make either of those w或k.
Another option is keeping the scripts purely in R, e.g. script.R
, and invoking it with R --file=script.R
或 similar. However, occasionally a script will rely on obscure command line switches at which point part of the code exists outside the script. Example: sneaking things into R from bash via a local .Rprofile, the desired switches are then everything --vanilla
implies except --no-init-file
.
Another option is a bash script to st或e the R flags and be painlessly executable, which then calls the R script. The problem is that this means a single program just got split into two files which now have to be keep in sync, transferred to new machines together, etc.
我目前最不喜欢的选项是在bash脚本中嵌入R:
#!/bin/bash
... # usage message to catch bad input without invoking R
... # any bash pre-processing of input
... # etc
R --random-flags <<RSCRIPT
# R code goes here
RSCRIPT
Everything's in a single file. It's executable and easily handles arguments. The problem is that combining bash and R like this pretty much eliminates the possibility of any IDE not failing on one 或 the other, and makes my heart hurt real bad.
有没有更好的方法让我错过?