Skip to contents

The import_data() function gets a specified data set from a package.
Unlike utils::data(), the import_data() function returns the data set directly, and allows assigning the data set like so:
mydata <- import_data(...).

Usage

import_data(package, dataname, lib.loc = .libPaths())

Arguments

package

a single string, giving the name of the R-package.

dataname

a single string, giving the name of the data set.

lib.loc

character vector specifying library search path (the location of R library trees to search through).
The lib.loc argument would usually be .libPaths().
See also loadNamespace.

Value

Returns the data directly. Thus, one can assign the data like so: mydata <- import_data(...).

See also

Examples


d <- import_data("datasets", "cars")
head(d)
#>   speed dist
#> 1     4    2
#> 2     4   10
#> 3     7    4
#> 4     7   22
#> 5     8   16
#> 6     9   10