Reputation: 44614
My R package has a dependency that needs a certain option set before it loads. Setting this option in the .onLoad
function of the zzz.r file of my package does not work, since the dependency appears to load before .onLoad
is called.
How can I guarantee that a certain option is set for the user of my package before its dependencies load?
Here is a link to a sample package that illustrates the situation: soExample.zip
The dependency in my example is the bartMachine package. The setting in question controls the amount of memory available to Java. When I'm using bartMachine in interactive mode, I can simply set the option, load bartMachine, and the startup message informs me that it has recognized the java.parameters
option I've set and made the requested amount of memory available to Java.
options(java.parameters='-Xmx5g')
library(bartMachine)
# ....
# Welcome to bartMachine v1.2.1! You have 4.77GB memory available.
However, when I load my package that depends on bartMachine, the java.parameter
option set in .onLoad
does not take effect in time and bartMachine makes only the default amount of memory available.
library(soExample)
# ....
# Welcome to bartMachine v1.2.1! You have 0.48GB memory available.
Upvotes: 4
Views: 960
Reputation: 69
I'm the maintainer of the package and I never thought about this scenario. A few questions:
Can you ship your user (you?) a local package (in a tar.gz file)?
Do you need the ability to customize the amount of RAM still?
What I was thinking is: you clone the code, you call options(java.parameters='-Xmx5g')
within the edited zzz.R after the jpackage on line 2 here. You do R CMD build bartMachine
to get a package, you send the package to the user and have them install locally.
Upvotes: 2