passing array from bash script to R Vector with a single argument -
i trying pass argument r script stored vector. have this:
script.sh
mylist="1,1,1,1,2,2,2,2" rscript ./script.r $mylist
script.r
args <- commandargs(trailingonly = true) myvector <- args[1] myvector[1] myvector[5]
the output i'm hoping is
"1" "2"
but instead i'm getting
[1] "1,1,1,1,2,2,2,2" [1] na
thanks in advance.
it's because mylist
single string, not vector of strings/numbers. try:
myvector <- unlist(strsplit(args[1],","))
Comments
Post a Comment