Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to handle dataset dependencies in package development?

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.

like image 670
Rich Scriven Avatar asked Nov 11 '22 07:11

Rich Scriven


1 Answers

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. 
    ...
}
like image 86
Rich Scriven Avatar answered Nov 15 '22 05:11

Rich Scriven