Skip to content

Instantly share code, notes, and snippets.

@loleg
Last active March 20, 2023 19:12
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/b543878d25b70085cef9cb4938544185 to your computer and use it in GitHub Desktop.
Save loleg/b543878d25b70085cef9cb4938544185 to your computer and use it in GitHub Desktop.
CKAN R Beispiel für BFH CAS
library('ckanr')
# Initialise the CKAN library with a remote portal
ckanr_setup(url = "https://opendata.swiss")
# Run a search to get some data packages
x <- package_search(q = 'video games', rows = 1)
# Note that on the Swiss server the titles are multilingual
x$results[[1]]$title$en
x$results[[1]]$url
# Get the URL of the first resource in the first package
tsv_url <- x$results[[1]]$resources[[1]]$url
# Download the remote (Tab Separated Values) data file
# ..and parse it in one step
raw_data <- read.csv(tsv_url, header=T, sep=",", skip=0)
head(raw_data, 1)
# Simple reformat of the column containing release year
ReleaseYear <- as.integer(substr(raw_data$released,0,4))
# Draw a simple plot of the first and second column
hist(ReleaseYear, breaks=10, xlab="Year")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment