[R] Pasting function arguments and strings

William Dunlap wdunlap at tibco.com
Wed Oct 13 18:39:10 CEST 2010


Is this the sort of thing you are looking for?

  > f <- function(testName, dataset, ...) {
  +     testFunc <- match.fun(paste(testName, "_test", sep=""))
  +     testFunc(dataset, ...)
  + }
  > m_test <- function(x) "the m test"
  > p_test <- function(x) "the p test"
  > f("m", 17)
  [1] "the m test"

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Manta
> Sent: Wednesday, October 13, 2010 9:29 AM
> To: r-help at r-project.org
> Subject: Re: [R] Pasting function arguments and strings
> 
> 
> Thaks for your quick reply Bert, although I doubt it works.
> 
> The reason is that the names of the objects of the dataset, 
> all end with the
> sufix '_test' and therefore I need to attach/paste/glue this 
> suffix to the
> 'arg2' of the function. Any other idea?
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/Pasting-function-arguments-and-s
trings-tp2993905p2993976.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.
> 



More information about the R-help mailing list