[BioC] function handle in R

Javier Pérez Florido jpflorido at gmail.com
Sat Feb 6 10:05:12 CET 2010


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
>



More information about the Bioconductor mailing list