Introduction
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.
Usage
You can download an entire dataset, or filter by date and/or
geography. We recommend filtering large datasets. If you require a full
download of a large dataset, you may need to contact statistics.gov.scot.
You will always need the last part of the URI for your dataset. Find this on the statistics.gov.scot web page for your dataset (in the API tab). For example, the full URI for Average Household Size is Average Household Size:
http://statistics.gov.scot/data/average-household-size
you just need the last part:
average-household-size
Without filtering
Once you have the last part of the URI, set this as the
dataset
parameter for ods_dataset()
:
household_size <- ods_dataset(dataset = "average-household-size")
head(household_size)
With filtering
Filtering is useful for large data sets. The filtering parameters for
ods_dataset()
are:
geography
Filter by geography
Specify a single geography type:
household_size_la <- ods_dataset(dataset = "average-household-size",
geography = "la")
head(household_size_la)
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.5 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
#>
#> locale:
#> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
#> [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
#> [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] opendatascot_0.0.0.9000
#>
#> loaded via a namespace (and not attached):
#> [1] digest_0.6.37 desc_1.4.3 R6_2.5.1 fastmap_1.2.0
#> [5] xfun_0.48 cachem_1.1.0 knitr_1.48 htmltools_0.5.8.1
#> [9] rmarkdown_2.28 lifecycle_1.0.4 cli_3.6.3 pkgdown_2.1.1
#> [13] sass_0.4.9 jquerylib_0.1.4 compiler_4.4.1 tools_4.4.1
#> [17] evaluate_1.0.1 bslib_0.8.0 yaml_2.3.10 jsonlite_1.8.9
#> [21] rlang_1.1.4 fs_1.6.4