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.