How to determine which variables or functions from a package are exported

My R package uses the internal variable x . If I download the package (I just tried using devtools::load_all ), then x does not appear in the ls() list, but it does matter. How can i avoid this?

I am fine when a user can access a variable using myPackage::x , but not just x .

+4
source share
2 answers

The load_all function has an export_all argument.

From ?load_all

If TRUE (default), export all objects. If FALSE, export only those objects that are specified as exports in the NAMESPACE file.

So try using export_all=FALSE in your call to load_all .

+7
source

First try creating a package and see if there is a problem. Export from the package is defined in the NAMESPACE file. When you use devtools::load_all , the namespace does not load (see here ). Learn more about this and creating a package in the Writing Extensions guide.

You may have used the default export template in your NAMESPACE file. Check it out in your package, and if it looks like this:

 exportPattern("^[^\\.]") 

then the package exports everything from the namespace that does not start with a dot. Therefore, you either call it .x or change exportPattern() to, for example ...

 export(myfun1, myfun2) 

to export the functions myfun1 and myfun2 from the package. By explicitly defining what you want to export, you avoid that something is available when it is not necessary.

+3
source

Source: https://habr.com/ru/post/1446708/


All Articles