I'm attempting to build a package that depends on some data from another package. Writing R Extensions says to avoid the use of require
in package functions. I may not use all the tables in the Lahman
package, and am currently importing them this way...
team.batting <- function(year, league, playoffs = FALSE)
{
...
Batting <- Lahman::Batting
Teams <- Lahman::Teams
## calculations, subsets, etc.
...
}
Is this correct? If not, what is the correct way to call an exported data set in a package function? And is the end user required to have the package installed for this to work?
Also, I'm not really clear on what a development version is, as compared to an installed version. If anyone could shed some light, I'd appreciate it.
After some research, I've determined the the correct way to do this is to include the directive
import(Lahman)
in the NAMESPACE file of my package (or possibly importFrom(Lahman, table name)
depending on how many tables are used). After doing this, the ::
calls can be removed.
team.batting <- function(year, league, playoffs = FALSE)
{
...
bat <- Batting
tms <- Teams
## calculations, subsets, etc.
...
}
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