[R] "unvector" ?

Rolf Turner rolf at erdos.math.unb.ca
Mon Sep 11 21:23:25 CEST 2006


Eric Elguero wrote:

> is there a way to pass a vector to a function
> expecting separate arguments?

	In general you can probably do something using

		do.call(FUN,as.list(v))

	where ``v'' is your vector.

> more specifically, I have a character vector, say u
> and I want a single string, but
> >paste(u) 
> doesn't work

	Yes it does if you do it right.  Read the help
	on paste().  (Hint:  There's an argument ``collapse''.)

>               so I would like something like 
> >paste(unvector(u)).
> 
> I am interested in a solution to the general problem too,
> as the only one I found is maintaining two versions of the
> functions I write.

	> v <- 1:3
	> do.call("paste",as.list(v))
	[1] "1 2 3"

	works, but this amounts to playing an unnecessary
	game of ring-around-the-rosy.

				cheers,

					Rolf Turner
					rolf at math.unb.ca



More information about the R-help mailing list