Resource

CKANR

Accessing open data with style

⛶  Fullscreen ↓  Download
Demo
Edit

The image above is a screenshot of an example R program running on RStudio Cloud. This uses the R library for CKAN to connect to opendata.swiss, data.stadt-zuerich.ch and other data portals which support the CKAN API. Why is this important?

  • You are using the latest version of the dataset;
  • Your program is showing each step of the data extraction process;
  • If there are notable changes to the data, including errors or improvements, they will soon be picked up;
  • Additional metadata that is not part of the dataset content can be useful to your process.

Try copying and adapting the code for yourself:

library('ckanr')

# Initialise the CKAN library with a remote portal
ckanr_setup(url = "https://data.stadt-zuerich.ch/")

# Run a search to get a list of datasets
datasearch <- package_search(q = 'frauen', rows=20)$results

# Take the first result available
opendataset = datasearch[[1]]

print(opendataset$title)
print(opendataset$resources[[1]]$name)

# Get the dataset contents through the first resource URL
csv_url = opendataset$resources[[1]]$url

# Read as CSV for further processing, visualisation..
csvdata <- read.csv(csv_url, header=T, sep=",")

Creative Commons LicenceThe contents of this website, unless otherwise stated, are licensed under a Creative Commons Attribution 4.0 International License.