66

Im working with the programming language R now. I have a vector:

a <- c("aa", "bb", "cc")

And I want to paste these to a system command, I'm trying it this way now:

args <- paste(a, sep=" ")
system(paste("command",args, sep=" "))

But now I'm only getting the arguments aa, and I want the arguments aa, bb and cc...

Anyone knows what I'm doing wrong?

Jetse
  • 1,755
  • 4
  • 15
  • 12
  • for your second paste(), i think instead of sep=" " do you want collapse=" " ? `system` is not vectorized but you are giving it three strings. – Anthony Damico Dec 20 '12 at 13:32

1 Answers1

150

Use the collapse argument to paste:

paste(a,collapse=" ")
[1] "aa bb cc"
James
  • 61,307
  • 13
  • 140
  • 186