While this could be done by setting the global environment, in my opinion, more clear, since the default behavior can be easily restored using the detach environment:
First, some demo functions, since I donβt know which package you wanted to use:
packageDemo <- new.env() makeFun <- function(x) {x;function(param) c(x, param)} for (i in paste0("f", letters)) assign(i, makeFun(i), packageDemo)
Now here is my curry package function. A character vector requires either an environment or a package name (for example, "package:myPackage" ). All functions in the environment are displayed in the currency and are added to the new environment, which is returned. Then it could be attach ed.
curryPackage <- function(package, ..., functionNames = NULL){ if (is.character(package) && !grepl("^package:", package)) { package <- paste0("package:", package) } fnNames <- ls(package) if (!is.null(functionNames)) { fnNames <- fnNames[fnNames %in% functionNames] } fnNames <- fnNames[vapply(fnNames, function(x) is.function(get(x, package)), logical(1))] fnList <- lapply(fnNames, function(x){ functional::Curry(get(x, package), ...) }) names(fnList) <- fnNames list2env(fnList) }
Now some demos
attach(packageDemo) fc("Testing") #[1] "fc" "Testing" fc() #Error in fc() : argument "param" is missing, with no default newPack <- curryPackage(packageDemo, param = "demo") attach(newPack) #The following objects are masked from packageDemo: # # fa, fb, fc, fd, fe, ff, fg, fh, fi, fj, fk, fl, fm, fn, fo, fp, fq, fr, fs, ft, fu, fv, fw, fx, fy, fz fc("Testing") #Error in (function (param) : unused argument ("Testing") fc() #[1] "fc" "demo"