在Rscript shebang行中包含参数时出错

w80xi6nr  于 2023-02-26  发布在  其他
关注(0)|答案(1)|浏览(152)

我正在尝试编写一个R脚本,它将作为Linux中的可执行文件运行。我不想在运行脚本或运行. Rprofile时打印出常规启动消息。但是,我希望在脚本中处理这一问题,并且不需要特定于R的参数。
我在网上搜索了一下,大多数指南都说把#!/usr/bin/env Rscript --vanilla放在最上面,但是这会抛出一个错误:

(base) balter@spectre:~$ cat readinr.R
#!/usr/bin/env Rscript --vanilla

print("hello")
(base) balter@spectre:~$ ./readinr.R
/usr/bin/env: ‘Rscript --vanilla’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
(base) balter@spectre:~$ R --version
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
oaxa6hgo

oaxa6hgo1#

虽然错误消息有点神秘,但stackexchange is更有帮助。您需要在shebang行中使用-S标志

#!/usr/bin/env -S Rscript --vanilla
cat("Also, not hello")

相关问题