Dear R wizards: under R-2.1.0: eargs <- 3:5; line <- paste(c("echo A B", eargs)); cat("executing from R: '", line, "'\n"); system(line); Oddly, only "A" and "B" are echoed, not the eargs. I had hoped that line would be one string at this point, and for printing this seems to be true. However, unlist(line) still gives me the 4 components. It almost seems like the objects were not really pasted, but kept separate [perhaps to conserve memory]---which works internally, but not externally. Is this my poor understanding of R, an R "feature," or an R bug? help appreciated. /iaw --- ivo welch
On Mon, 15 Aug 2005 ivo_welch-rstat8303 at mailblocks.com wrote:> > Dear R wizards: > > under R-2.1.0: > > eargs <- 3:5; > line <- paste(c("echo A B", eargs)); > cat("executing from R: '", line, "'\n"); > system(line); > > Oddly, only "A" and "B" are echoed, not the eargs. I had hoped that > line would be one string at this point, and for printing this seems to > be true. However, unlist(line) still gives me the 4 components. It > almost seems like the objects were not really pasted, but kept separate > [perhaps to conserve memory]---which works internally, but not > externally. > > Is this my poor understanding of R, an R "feature," or an R bug? >It's your understanding. Look at the `collapse' argument to paste(). -thomas
On 8/15/05, ivo_welch-rstat8303 at mailblocks.com <ivo_welch-rstat8303 at mailblocks.com> wrote:> > Dear R wizards: > > under R-2.1.0: > > eargs <- 3:5; > line <- paste(c("echo A B", eargs)); > cat("executing from R: '", line, "'\n"); > system(line); > > Oddly, only "A" and "B" are echoed, not the eargs. I had hoped that > line would be one string at this point, and for printing this seems to > be true. However, unlist(line) still gives me the 4 components. It > almost seems like the objects were not really pasted, but kept separate > [perhaps to conserve memory]---which works internally, but not > externally. > > Is this my poor understanding of R, an R "feature," or an R bug?Poor understanding but the mistake is a common one. If you want to form a character vector of length 1 you must use the "collapse" argument to paste(). Try> eargs <- 3:5 > paste("echo A B", paste(eargs, collapse = " "))[1] "echo A B 3 4 5">
ivo_welch-rstat8303 at mailblocks.com wrote:> Dear R wizards: > > under R-2.1.0: > > eargs <- 3:5; > line <- paste(c("echo A B", eargs)); > cat("executing from R: '", line, "'\n"); > system(line); > > Oddly, only "A" and "B" are echoed, not the eargs. I had hoped that > line would be one string at this point, and for printing this seems to > be true. However, unlist(line) still gives me the 4 components. It > almost seems like the objects were not really pasted, but kept separate > [perhaps to conserve memory]---which works internally, but not > externally. > > Is this my poor understanding of R, an R "feature," or an R bug?Feature: The arguments of paste() get pasted, and you have just specified one argument which is a character *vector*. You want to say that the elements of the vector should be pasted as follows: line <- paste(c("echo A B", eargs), collapse = " ") Uwe Ligges> help appreciated. > > /iaw > > > --- > ivo welch > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html