Skip to content

Instantly share code, notes, and snippets.

@loleg
Created March 20, 2023 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loleg/62a5757715f8d08af1b4fcf2ffcb567a to your computer and use it in GitHub Desktop.
Save loleg/62a5757715f8d08af1b4fcf2ffcb567a to your computer and use it in GitHub Desktop.
R example usage of Frictionless Data library
library(frictionless) # https://docs.ropensci.org/frictionless/
library(readr) # https://readr.tidyverse.org/reference/problems.html
# Read contents of a Data Package
package_local <- read_package("velozuerich/datapackage.json")
resources(package_local)
resource_local = read_resource(package_local, "velonetz-csv")
# Preview the first few rows
head(resource_local)
# Draw a simple plot of the numeric columns
plot(resource_local$objectid, resource_local$length)
# Read from another package (note: avoid renaming datapackage.json)
package_quatch <- read_package("velozuerich/datapackage-quatch.json")
resources(package_quatch)
# Read and validate the resource
resource_quatch = read_resource(package_quatch, "veloquatch-csv")
head(resource_quatch)
# Use tidyverse/readr to explain the problem with the data
problems(resource_quatch)
# Add more resources to a Data Package
schema_local <- get_schema(package_local, "velonetz-csv")
another_file <- system.file("veloquatch",
"velozuerich/veloquatch.csv",
package="frictionless")
another_resource <- add_resource(
package_local, "velonetz-broken", "velozuerich/veloquatch.csv",
schema = schema_local, delim = ",")
# Read from a remote package
package_remote <- read_package("https://raw.githubusercontent.com/loleg/baumkataster-data/master/datapackage.json")
resources(package_remote)
resource_remote <- read_resource(package_remote, "preview")
head(resource_remote)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment