Erik Iverson wrote:
Hello,

Jeff Brown wrote:

I would expect the following:

paste(
as.character( cat( rep( ".", 2 ) ) ), "a string",
    as.character( cat( rep( ".", 3 ) ) )
);

to yield this string: ". . a string . . .", but instead it yields this:

. .. . .[1] " a string "


cat is writing its output to the console, not creating an object like you want. notice the second cat will return (and write to the console) before paste.

You need the collapse argument to paste, forget about cat for this.

Try:

pc <- function(...) paste(..., collapse = " ")
rd <- function(n) rep(".", n)
pc(pc(rd(2)), "a string", pc(rd(3)))



Or even a little bit "DRY"er:

pc <- function(...) paste(..., collapse = " ")
rd <- function(n) pc(rep(".", n))
pc(rd(2), "a string", rd(3))

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to