命令行在bash参数RSCRIPT [英] command line arguments in bash to Rscript

查看:220
本文介绍了命令行在bash参数RSCRIPT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建一个CSV文件,从创建图表的R档bash脚本。

I have a bash script that creates a csv file and an R file that creates graphs from that.

在bash脚本我通话结束 RSCRIPT Graphs.R 10

At the end of the bash script I call Rscript Graphs.R 10

我得到的答复如下:

Error in is.vector(X) : subscript out of bounds
Calls: print ... <Anonymous> -> lapply -> FUN -> lapply -> is.vector
Execution halted

我Graphs.R的前几行是:

The first few lines of my Graphs.R are:

#!/bin/Rscript
args <- commandArgs(TRUE)
CorrAns = args[1]

不知道我做错了吗?在网上的意见,在我看来说,这应该工作。它很难让 commandArgs

推荐答案

随着args.R以下

print(commandArgs(TRUE)[1])

和在args.sh以下

and the following in args.sh

Rscript args.R 10

我从庆典args.sh

[1] "10"

和没有错误。如果有必要,使用 as.numeric转换为数字小类型(commandArgs(TRUE)[1])

and no error. If necessary, convert to a numberic type using as.numeric(commandArgs(TRUE)[1]).

这篇关于命令行在bash参数RSCRIPT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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