knitr::opts_chunk$set(
  echo = TRUE,
  eval = TRUE,
  comment = "#>",
  fig.path = "README-"
)

opendatascot opendatascot logo

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

Use opendatascot to download data from statistics.gov.scot with a single line of R code. opendatascot removes the need to write SPARQL code; you simply need the URI of a dataset. opendatascot can be used interactively, or as part of a Reproducible Analytical Pipeline (RAP).

Installation

If you are working within the Scottish Government network, you can install opendatascot in the same way as with other R packages. The easiest way to do this is by using the pkginstaller add-in. Further guidance is available on eRDM.

Alternatively, opendatascot can be installed directly from GitHub. Note that this method requires the devtools package and may not work from within the Scottish Government network.

devtools::install_github(
  "ScotGovAnalysis/opendatascot",
  upgrade = "never",
  build_vignettes = TRUE
)

Finally, opendatascot can also be installed by downloading the zip of the repository and running the following code, replacing the section marked <> (including the arrows themselves) with the location of the downloaded zip:

devtools::install_local(
  "<FILEPATH OF ZIPPED FILE>/opendatascot-main.zip",
  upgrade = "never",
  build_vignettes = TRUE
)

Usage

Learn more in vignette("opendatascot") or ?ods_dataset.

ods_all_datasets() finds all datasets currently loaded onto statistics.gov.scot, and their publisher

ods_dataset() returns data from a dataset in statistics.gov.scot

ods_structure() finds the full sets of categories and values for a particular dataset (helpful for creating new filters for ods_dataset!)

ods_print_query() produces the SPARQL query used by ods_dataset().

ods_find_higher_geography() and ods_find_higher_geography() will find all geographical areas with contain, or are contained by a specified geography.

Examples

Get a dataframe of all datasets on statistics.gov.scot, their uri, and publisher

opendatascot::ods_all_datasets()

Discover the structure of the dataset on homelessness applications - so we can use this in a later filter

opendatascot::ods_structure("homelessness-applications")

After viewing the structure, we decide we only want the data for "all-applications" and for the periods "2015/2016" and "2016/2017", so we add these to the filter.

opendatascot::ods_dataset("homelessness-applications",
                          applicationType = "all-applications",
                          refPeriod = c("2015/2016", "2016/2017"))

If you're only interested in a particular geographical level, you can use the "geography" argument to return only specific levels.

opendatascot::ods_dataset("homelessness-applications",
                          geography = "la")

Option for geography are:
"dz" - returns datazones only
"iz" - returns intermediate zones only
"hb" - returns healthboards only
"la" - returns local authorities only
"sc" - returns Scotland as a whole only

Geography manipulation

If you're looking for information about what geographies are contained by, or containing, other geographies, there are two handy functions to help - ods_find_lower_geographies() will return a dataframe of all geographies that are contained by the geography you pass it ods_find_higher_geographies() will return a dataframe of all geographies that contain the geography you pass it

all_zones_in_iz <- opendatascot::ods_find_lower_geographies("S02000003")
all_zones_in_iz

This dataframe can then be passed to ods_dataset to get information about these geographies! We just need to select the vector of geography codes, and use the refArea filter option:

opendatascot::ods_dataset("house-sales-prices",
                          refArea = all_zones_in_iz$geography,
                          measureType = "mean",
                          refPeriod = "2013")

Future development

This package is under active development, so any further functionality will be mentioned here when it’s ready. If something important is missing, feel free to contact the contributors or add a new issue.

Since this package is under active development, breaking changes may be necessary. We will make it clear once the package is reasonably stable.



jsphdms/scotgov documentation built on Oct. 16, 2024, 6 p.m.