csodata quick start guide

2021-10-07

Introduction

This guide provides a basic overview of the use of the csodata package for new users. Install (if necessary) and load the package:

# # Install or update the package:
# install.packages("csodata")

library(csodata)

Table of Contents

A list of all the table available on the cso StatBank can be downloaded with cso_get_toc. You can search throught the title field using cso_search_toc. (A “Loaded cached toc” or “Loaded cached data” message indicates that the data was retrieved from the cache, instead of being downloaded again.)

toc <- cso_get_toc()
head(toc)
#>          LastModified
#> 1 2021-10-07 00:20:00
#> 2 2021-10-07 00:20:00
#> 3 2021-10-07 00:20:00
#> 4 2021-10-07 00:20:00
#> 5 2021-10-07 00:20:00
#> 6 2021-10-07 00:20:00
#>                                                                           title
#> 1                                   2002 Private Households with Irish Speakers
#> 2                                             Population Aged 15 Years and Over
#> 3                                     2002 Irish Speakers in Private Households
#> 4                   2002 Private Households where Reference Person Speaks Irish
#> 5                                             Population Aged 15 Years and Over
#> 6 2002 Irish Speakers in Private Households where Reference Person Speaks Irish
#>      id
#> 1 B1116
#> 2 C0702
#> 3 B1117
#> 4 B1118
#> 5 C0703
#> 6 B1119

Downloading Data

To download a dataset, use cso_get_data.

tbl1 <- cso_get_data("PEA19")

Metadata can be also downloaded or displayed to console:

meta1 <- cso_get_meta("CDP06")
cso_disp_meta("CDP06")
#> Loaded cached data
#> *** METADATA ***
#> CSO Table = Annual Estimated Net Migration 1951 to 2011 per 1,000 of Average Population
#> Units = Number
#> Copyright = Central Statistics Office, Ireland
#> Time interval in data = Year
#> Are these statistics experimental? -FALSE
#> Date last modified = 2020-10-30T11:00:00Z
#> Variables:
#> [1] "Year"               "Intercensal Period" "Province or County"
#> 
#> Statistics:
#> [1] "Annual Estimated Net Migration 1951 to 2011 per 1,000 of Average Population"

Geographic Data

Geographic vector data in ESRI shapefile format can be downloaded for use in mapping. This uses the older 2011 data, which includes demographic information. Newer maps, including the revisions to the NUTS regions made in 2016, is also available.

shp <- cso_get_geo("NUTS3_2011")
#> Reading layer `Census2011_NUTS3_generalised20m' from data source `C:\Users\crowleyco\AppData\Local\Temp\RtmpE35OZ7\Census2011_NUTS3_generalised20m.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 8 features and 18 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 17491.14 ymin: 19589.93 xmax: 334558.6 ymax: 466919.3
#> Projected CRS: TM65 / Irish Grid

This data can be plotted using the tmap package. Here we plot the 2011 population, which is included as the “TOTAL2011” column in the map data.

# install.packages("tmap")
library(tmap)
#> Warning: package 'tmap' was built under R version 4.0.5

t <- tm_shape(shp) +
       tm_fill(col="TOTAL2011", 
                    palette = viridisLite::viridis(20),
                    style="cont", legend.reverse = TRUE,
                    title = "Population 2011") +
       tm_borders(col = "black") +
       tm_layout(frame = FALSE, scale = 1.3)
t

The data which has been cached locally can be manually cleared once we are done with it.

cso_clear_cache()