View source: R/read_resource.R
read_resource | R Documentation |
Reads data from a Data Resource (in a Data Package) into a tibble (a
Tidyverse data frame).
The resource must be a Tabular Data Resource.
The function uses readr::read_delim()
to read CSV files, passing the
resource properties path
, CSV dialect, column names, data types, etc.
Column names are taken from the provided Table Schema (schema
), not from
the header in the CSV file(s).
read_resource(package, resource_name, col_select = NULL)
package |
Data Package object, as returned by |
resource_name |
Name of the Data Resource. |
col_select |
Character vector of the columns to include in the result, in the order provided. Selecting columns can improve read speed. |
See vignette("data-resource")
, vignette("table-dialect")
and
vignette("table-schema")
to learn how this function implements the
Data Package standard.
A tibble::tibble()
with the Data Resource's tabular data.
If there are parsing problems, a warning will alert you.
You can retrieve the full details by calling problems()
on your data
frame.
Other read functions:
read_package()
,
resources()
# Read a datapackage.json file
package <- read_package(
system.file("extdata", "v1", "datapackage.json", package = "frictionless")
)
package
# Read data from the resource "observations"
read_resource(package, "observations")
# The above tibble is merged from 2 files listed in the resource path
package$resources[[2]]$path
# The column names and types are derived from the resource schema
purrr::map_chr(package$resources[[2]]$schema$fields, "name")
purrr::map_chr(package$resources[[2]]$schema$fields, "type")
# Read data from the resource "deployments" with column selection
read_resource(package, "deployments", col_select = c("latitude", "longitude"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.