[R] Trying to build up functions with its names by means of lapply

Bert Gunter gunter.berton at gene.com
Thu Jun 6 17:48:36 CEST 2013


Sergio:

Fair question.

Unfair answer: My personal hangup. To my taste, get() makes R like a
macro language instead of doing functional programming. force() makes
me nervous about how I'm passing arguments. I won't attempt to defend
either of these claims, so feel free to dismiss.

Cheers,
Bert

On Thu, Jun 6, 2013 at 8:28 AM, Julio Sergio <juliosergio at gmail.com> wrote:
> Bert Gunter <gunter.berton <at> gene.com> writes:
>
>> Another equivalent way to do it?
>>
>> f2 <- function(c,nm = "gamma",...)
>> {
>>   probFunc <- paste0(c,nm)
>>   more <- list(...)
>>   function(x)do.call(probFunc,c(x,more))
>> }
>>
>> This avoids the explicit use of get() and force(), I believe, but are
>> there problems here I'm missing?
>>
>
> Thanks Bert. Since I'm relatively new in using this language, a question
> arises in my mind: why should the use of get() and force() be avoided? Is it
> just for syntactic clarity or is there another computational reason?
>
> Best regards,
>
>   -Sergio.
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list