function handle in R
2
0
Entering edit mode
@javier-perez-florido-3121
Last seen 6.1 years ago
Dear list, Is there any way to use function handle in R? I would like to do something like this (is written in MATLAB) handleFunction=@function1; handleFunction(arguments) # MATLAB knows that handleFunction is related to function1 Thus, handleFunction can be any function, for example: handleFunction=@function1 or handleFunction=@function2 or handleFunction=@function3, etc the function call is always the same handleFunction(arguments) Any ideas? Thanks, Javier
• 2.8k views
ADD COMMENT
0
Entering edit mode
@arunava-chakravartty-3910
Last seen 9.6 years ago
Javier, This can be done very easily in R. In fact every function in R is treated as just another object. Here's an eg. > f1<-function(x) length(x) > f2<-f1 > class(f1) [1] "function" > attributes(f1) $source [1] "function(x) length(x)" > length(f1) [1] 1 > formals(f1) $x So you see you can fetch any parameter of the function using the right function. Regards, Arunava 2010/1/30 Javier Pérez Florido <jpflorido@gmail.com> > Dear list, > Is there any way to use function handle in R? I would like to do something > like this (is written in MATLAB) > > handleFunction=@function1; > handleFunction(arguments) # MATLAB knows that handleFunction is related to > function1 > > Thus, handleFunction can be any function, for example: > handleFunction=@function1 or handleFunction=@function2 or > handleFunction=@function3, etc > > the function call is always the same > handleFunction(arguments) > > Any ideas? > Thanks, > Javier > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > -- Arunava Chakravartty 13735 Luxor Chase, Fishers,IN 46038 [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
@wolfgang-huber-3550
Last seen 18 days ago
EMBL European Molecular Biology Laborat…
Dear Javier Functions in R are just variables like everyone else, so you can simply write: handleFunction=function1 or handleFunction=function2 etc. Have a look into the book by Robert Gentleman http://www.bioconductor.org/pub/RBioinf or the online introduction to R http://cran.r-project.org/doc/manuals/R-intro.html esp. chapter 10. This might save you a lot of time. Best wishes Wolfgang Javier P?rez Florido wrote: > Dear list, > Is there any way to use function handle in R? I would like to do > something like this (is written in MATLAB) > > handleFunction=@function1; > handleFunction(arguments) # MATLAB knows that handleFunction is related > to function1 > > Thus, handleFunction can be any function, for example: > handleFunction=@function1 or handleFunction=@function2 or > handleFunction=@function3, etc > > the function call is always the same > handleFunction(arguments) > > Any ideas? > Thanks, > Javier > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor -- Best wishes Wolfgang -- Wolfgang Huber EMBL http://www.embl.de/research/units/genome_biology/huber/contact
ADD COMMENT

Login before adding your answer.

Traffic: 895 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6