从呼叫传递参数给一个bash脚本到RSCRIPT [英] Passing arguments from a call to a bash script to an Rscript

查看:448
本文介绍了从呼叫传递参数给一个bash脚本到RSCRIPT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,做一些事情,然后调用RSCRIPT。在这里,一个简单的例子来说明:

I have a bash script that does some things and then calls Rscript. Here a simple example to illustrate:

test.sh:

Rscript test.r

test.r:

args <- commandArgs()
print(args)

如何使用 ./ test.sh你好上打印命令行结果中的R你好?

How can I use ./test.sh hello on the command line result in R printing hello?

推荐答案

您可以使用bash的像这样的bash脚本传递所有参数到R脚本:

You can have bash pass all the arguments to the R script using something like this for a bash script:

#!/bin/bash

Rscript /path/to/R/script --args "$*"

exit 0

您可以再选择多少从$参数*需要的R内被丢弃。

You can then choose how many of the arguments from $* need to be discarded inside of R.

这篇关于从呼叫传递参数给一个bash脚本到RSCRIPT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆