Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

use_data

Create package data


Description

use_data() makes it easy to save package data in the correct format. I recommend you save scripts that generate package data in data-raw: use use_data_raw() to set it up. You also need to document exported datasets.

Usage

use_data(
  ...,
  internal = FALSE,
  overwrite = FALSE,
  compress = "bzip2",
  version = 2
)

use_data_raw(name = "DATASET", open = rlang::is_interactive())

Arguments

...

Unquoted names of existing objects to save.

internal

If FALSE, saves each object in its own .rda file in the data/ directory. These data files bypass the usual export mechanism and are available whenever the package is loaded (or via data() if LazyData is not true).

If TRUE, stores all objects in a single R/sysdata.rda file. Objects in this file follow the usual export rules. Note that this means they will be exported if you are using the common exportPattern() rule which exports all objects except for those that start with ..

overwrite

By default, use_data() will not overwrite existing files. If you really want to do so, set this to TRUE.

compress

Choose the type of compression used by save(). Should be one of "gzip", "bzip2", or "xz".

version

The serialization format version to use. The default, 2, was the default format from R 1.4.0 to 3.5.3. Version 3 became the default from R 3.6.0 and can only be read by R versions 3.5.0 and higher.

name

Name of the dataset to be prepared for inclusion in the package.

open

Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise.

See Also

Examples

## Not run: 
x <- 1:10
y <- 1:100

use_data(x, y) # For external use
use_data(x, y, internal = TRUE) # For internal use

## End(Not run)
## Not run: 
use_data_raw("daisy")

## End(Not run)

usethis

Automate Package and Project Setup

v2.0.1
MIT + file LICENSE
Authors
Hadley Wickham [aut] (<https://orcid.org/0000-0003-4757-117X>), Jennifer Bryan [aut, cre] (<https://orcid.org/0000-0002-6983-2759>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.