[BioC] function handle in R

Vincent Carey stvjc at channing.harvard.edu
Sat Feb 6 11:56:31 CET 2010


use "get"

e.g., if "myexpresso" is the string naming a function then
get("myexpresso") evaluates to the function and
get("myexpresso")(...) is valid R applying that function to ...

do.call("myexpresso", list(...)) is also relevant

[note that i have not followed your whole correspondence ... but for
the question posed in this email, get() is your solution]

2010/2/6 Javier Pérez Florido <jpflorido at gmail.com>:
> Thanks Wolfgang and Arunava,
>
> What I would like to do is the following:
> I have the following character vector:
> functionsUsed=c("myexpresso","mythreestep","myvsnrma","myl.farms","myjustPlier","mymmgmos","myexp.farms","myrma","mymas5","myq.farms")
>
> For each component in this vector, I have a function defined:
> myexpresso<-function(rawData,<otherarguments>),
> mythreestep<-function(rawData,<otherarguments>), etc
>
> From a file, I read a 'listOfFunctions' character vector of unknown length.
> This vector contains names like the ones given in functionsUsed vector:
> "myexpresso", "myvsnrma", etc.... Let's say,
> listOfFunctions=c("mythreestep","myvsnrma","mythreestep","mymas5","myexpresso","myexpresso")
>
> I would like to call the functions related to this vector:
>
>   for(i in 1:length(listOfFunctions)
>   {
>       currentFunction=listOfFunctions[i]:
>       eset<-currentFunction(rawData,<otherarguments>)
>    }
>
> The problem is that currentFunction is a character string, not a function
> and I cannot convert this character string to an object of function class.
>
> I can proceed with if/then/else blocks, but I think there must be a smart
> way to do this.
>
> Thanks again,
> Javier
>
>
>
>
> Wolfgang Huber escribió:
>>
>> 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
>>
>
> _______________________________________________
> 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
>



More information about the Bioconductor mailing list