質問

My R package uses an internal variable x. If I load the package (I've only tried using devtools::load_all), then x doesn't appear in the ls() list, but it does have a value. How can I avoid this?

I'm fine with the user being able to access the variable with myPackage::x, but not simply x.

役に立ちましたか?

解決

The load_all function has an export_all argument.

From ?load_all

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

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

他のヒント

Try building the package first, and check whether the problem still exists. The exports from a package are defined in the NAMESPACE file. When you use devtools::load_all, the namespace isn't loaded ( see here). Read more about this and building a package in the manual Writing R extensions.

You might be using a default export pattern in your NAMESPACE file. Check it in your package, and if it looks like this:

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

then the package exports everything from the namespace that doesn't start with a dot. So you either call it .x, or you change the exportPattern() to eg...

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's available when there's no need for that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top