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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -