Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically load data in an R package?

Tags:

package

r

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?

like image 647
Tyler Rinker Avatar asked Jun 05 '12 03:06

Tyler Rinker


People also ask

How do I load data into an R package?

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.

Which R function is used to load a 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.

How do I see data in an R package?

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").


1 Answers

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
like image 136
Dason Avatar answered Oct 21 '22 04:10

Dason