Skip to contents

Downloads a dataset from the Rdatasets archive and returns it as a data frame.

https://vincentarelbundock.github.io/Rdatasets/

Usage

rddata(dataset, package = NULL)

Arguments

dataset

String. Name of the dataset to download from the Rdatasets archive. Use rdsearch() to search available datasets.

package

String. Package name that originally published the data. If NULL, the function will attempt to automatically detect the package by searching for an exact match in the Rdatasets index.

Value

A data frame containing the dataset. The columns and rows vary based on the dataset.

Details

If the nanoparquet package is installed, rddata() will use the Parquet format, which is faster and uses less bandwidth to download. If nanoparquet is not available, the function automatically falls back to CSV format using base R functionality.

Global Options

The following global options control package behavior:

  • Rdatasets_cache: Logical

    • Whether to cache downloaded data and index for faster subsequent access. Default: TRUE. Please keep this option TRUE as it makes repeated access faster and avoids overloading the Rdatasets server. Only set to FALSE if local memory is severely limited.

    • Ex: `options(Rdatasets_cache = TRUE)“

  • Rdatasets_class: String

    • Output class of the returned data. One of "data.frame" (default), "tibble", or "data.table". Default: "data.frame". Requires the respective packages to be installed for "tibble" or "data.table" formats.

    • Ex: options(Rdatasets_class = "tibble")

  • Rdataset_path: String.

    • Base URL for the Rdatasets archive. Default: "https://vincentarelbundock.github.io/Rdatasets/". Advanced users can set this to use a different mirror or local copy.

    • Ex: options(Rdataset_path = "https://vincentarelbundock.github.io/Rdatasets/")

Examples

dat <- rddata("Titanic", "Stat2Data")
head(dat)
#>   rownames                                          Name PClass   Age    Sex
#> 1        1                  Allen, Miss Elisabeth Walton    1st 29.00 female
#> 2        2                   Allison, Miss Helen Loraine    1st  2.00 female
#> 3        3           Allison, Mr Hudson Joshua Creighton    1st 30.00   male
#> 4        4 Allison, Mrs Hudson JC (Bessie Waldo Daniels)    1st 25.00 female
#> 5        5                 Allison, Master Hudson Trevor    1st  0.92   male
#> 6        6                            Anderson, Mr Harry    1st 47.00   male
#>   Survived SexCode
#> 1        1       1
#> 2        0       1
#> 3        0       0
#> 4        0       1
#> 5        1       0
#> 6        1       0