0

First of all, sorry that I do not provide a fully reproducible example, but I'm using the devel version of a BioConductor package and the installation is a bit of a pain in the butt.

I am trying to use do.call to invoke functions based on a string I paste together. Like so:

testfunction <- function(){
  print("do.call is working")
}

do.call(paste("test", "function", sep = ""), args = list())

This prints:

"do.call is working"

When I am trying to invoke my function of interest, like so:

for (dataset in unique(metadata[, 1])){
  replace_idx <- which(metadata[,1 ] == dataset)
  do.call(paste('curatedMetagenomicData::', dataset, ".genefamilies_relab.stool", sep = ""), args = list())
  if (length(replace_idx) > 0){
    # Do further stuff.
  }
}

I get this error:

Error in curatedMetagenomicData::ZellerG_2014.genefamilies_relab.stool() :
could not find function "curatedMetagenomicData::ZellerG_2014.genefamilies_relab.stool"

Invoking the function outside of the loop, without do.call, works.

Could this be an environment problem of some sort? Any help is greatly appreciated.

PejoPhylo
  • 469
  • 2
  • 11
  • You might consider to use get(paste("test", "function", sep = "")) or if that don't work build the hole command as a string <- "do.call(....)" and use eval(parse(text=string)). – AaronP Oct 06 '17 at 09:00
  • Perhaps use `f <- match.fun(paste0('curatedMetagenomicData::', dataset, ".genefamilies_relab.stool"))`, and see if you can grab the function, then use `do.call(f, args = list())`. Can't test. – Axeman Oct 06 '17 at 09:08
  • I couldn't get anything of that sort to work. I managed to solve my problem, though, by omitting the "curatedMetagenomicData::" part. The simple do.call did the job, then. Thanks for your help, anyway :) – PejoPhylo Oct 06 '17 at 09:14

0 Answers0