Student T Student T - 1 year ago 51
R Question

"Found the following calls to data() loading into the global environment"

In my R-package, I have:

f <- function()
data('MyDataSet') # Load a dataset in my own package
... # Use MyDataSet to return something

The package builder has a warning message:

Found the following calls to data() loading into the global environment

What is the easiest way to fix the problem? Can I just load the data set into a variable? I don't need to save it to the global environment.

Answer Source


I tested this and I could built the package without problems.

What gave me your note (not a warning, not a error) was actually performing the check() for the package.


This is first of all important if you want to put the package on CRAN. Since the package will be very likely rejected if you do not have 0 notes, 0 warning, 0 errors.

If you just want to use the package for your own, you could also just leave it as it is. Since the check looks for coding guidelines and performs other useful things it indeed also may make sense to fix this for your private package.


One solution could be to include this dataset in your package itself. You have to create a folder called data in your package to do this. Add the dataset as .rda file there. I think in your package description LazyData: TRUE has also to be set. (think this is the default).

Now you can write the following:

f <- function()
    x <- MyPackageName::MyDataSet
    ... # Use MyDataSet to return something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download