Hi ev'rybody, is there a way to pass a vector to a function expecting separate arguments? more specifically, I have a character vector, say u and I want a single string, but>paste(u)doesn't work, 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. Eric Elguero GEMI-UMR 2724 IRD-CNRS, Equipe "Evolution des Systemes Symbiotiques" 911 avenue Agropolis, BP 64501, 34394 Montpellier cedex 5 FRANCE
Try:> paste(letters, collapse=' ')Or> do.call('paste',as.list(letters))-- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Eric Elguero Sent: Monday, September 11, 2006 9:08 AM To: r-help at stat.math.ethz.ch Subject: [R] "unvector" ? Hi ev'rybody, is there a way to pass a vector to a function expecting separate arguments? more specifically, I have a character vector, say u and I want a single string, but>paste(u)doesn't work, 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. Eric Elguero GEMI-UMR 2724 IRD-CNRS, Equipe "Evolution des Systemes Symbiotiques" 911 avenue Agropolis, BP 64501, 34394 Montpellier cedex 5 FRANCE ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.
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 workYes 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
"Eric Elguero" <Eric.Elguero at mpl.ird.fr> writes:> Hi ev'rybody, > > is there a way to pass a vector to a function > expecting separate arguments? > more specifically, I have a character vector, say u > and I want a single string, but > >paste(u) > doesn't work, 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.In general, something like do.call("foo", as.list(args)), for paste() in particulare, notice e.g. collapse=" ". -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907