Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export all hidden functions from a package

Is there a way to automatically import all hidden functions from a package, ie functions accessible only with package:::fun ?

Indeed I have brought some modifications to a given function which uses quite a lot of internal functions and I want to avoid retyping package::: everywhere.

I looked at loadNamespace base function but it does not attach the non exported ones.

like image 512
ClementWalter Avatar asked Jun 15 '16 10:06

ClementWalter


1 Answers

Ok I finally found sort of a hack using this related post and eval:

# get all the function names of the given package "mypack"
r <- unclass(lsf.str(envir = asNamespace("mypack"), all = T))

# filter weird names
r <- r[-grep("\\[", r)]
r <- r[-grep("<-", r)]

# create functions in the Global Env. with the same name
for(name in r) eval(parse(text=paste0(name, '<-mypack:::', name)))

I would have thought there were some prebuilt function to do this anyway.

like image 157
ClementWalter Avatar answered Oct 22 '22 18:10

ClementWalter