Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Base function that behaves like `cat` but returns value instead of writing to file

Tags:

string

r

I am sick and tired of writing:

paste(paste(letters[1:3], collapse=" "), "foo")

In order to get:

[1] "a b c foo"

particularly because the collapse argument must be fully typed since it follows the .... cat does this very easily:

cat(letters[1:3], "foo")

but does not return a value (grrr). Is there any base (or otherwise R default preloaded package) function that behaves like cat does and actually returns a value?

Clearly there are several ways of building such a function, but I can't believe there isn't something already pre-existing.

One possible semi-okay solution I just thought of:

paste(c(letters[1:3], "foo"), collapse=" ")

But again annoying because of the need to fully type out collapse.

like image 604
BrodieG Avatar asked Apr 24 '15 13:04

BrodieG


1 Answers

You could try

Reduce(paste, c(letters[1:3], 'foo'))
like image 51
akrun Avatar answered Nov 11 '22 16:11

akrun