This is likely an easy answer that's been answered numerous times. I just lack the terminology to search for the answer.
I'm creating a package. When the package loads I want to have instant access to the data sets.
So lets say DICTIONARY is a data set.
I want to be able to do DICTIONARY
rather than data(DICTIONARY)
to get it to load. How do I go about doing this?
The default R datasets included in the base R distribution Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.
packages() , which as you can expect, installs a given package. library() which loads packages, i.e. attaches them to the search list on your R workspace.
To get the list of available data sets in base R we can use data() but to get the list of data sets available in a package we first need to load that package then data() command shows the available data sets in that package. Also, for data sets in base R, we can use ls("package:datasets").
From R-exts.pdf (online source):
The ‘data’ subdirectory is for data files, either to be made available via lazy-loading or for loading using data(). (The choice is made by the ‘LazyData’ field in the ‘DESCRIPTION’ file: the default is not to do so.)
Adding the following to the DESCRIPTION file should do it:
LazyData: true
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