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
.
Export functions are functions that a module exposes to other modules. They can be thought of as the module's interface. Dependency Walker uses the exported list to check for unresolved external errors in the selected module.
Use named exports to export multiple variables in JavaScript, e.g. export const A = 'a' and export const B = 'b' . The exported variables can be imported by using a named import as import {A, B} from './another-file. js' . You can have as many named exports as necessary in a file.
In Go, a name is exported if it begins with a capital letter. For example, Pizza is an exported name, as is Pi , which is exported from the math package. pizza and pi do not start with a capital letter, so they are not exported.
The import function imports text data by converting from external text representation to the internal format. The export function exports text data by converting from the internal format to the external text representation.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With