
Fetch a Statistics Canada NDM / cansim table
Source:R/ingest_statcan.R
morie_ingest_statcan_cansim.RdConvenience wrapper around the CRAN cansim package, which
talks to the Statistics Canada NDM ("cansim") tabular data API.
Use this for canonical CANSIM tables (e.g. "35-10-0177-01")
rather than for PUMF _CSV.zip downloads — those go
through morie_ingest_statcan_csv.
Usage
morie_ingest_statcan_cansim(
table_id,
language = c("eng", "fra"),
refresh = FALSE,
...
)Arguments
- table_id
A StatCan / NDM table identifier, e.g.
"35-10-0177"or"35-10-0177-01".- language
One of
"eng"or"fra".- refresh
If
TRUE, force cansim to re-download rather than using its on-disk cache.- ...
Further arguments forwarded to
get_cansim.
Details
No credentials are required: the StatCan Web Data Service is
public. Setting the optional STATCAN_API_KEY environment
variable only raises your WDS rate limits; without it the fetch
still works (it is forwarded to cansim via the
CANSIM_API_KEY name the package reads internally).
Examples
# \donttest{
# Requires the 'cansim' package and network access.
df <- morie_ingest_statcan_cansim("35-10-0177")
head(df)
#> REF_DATE GEO DGUID Violations
#> 1 1998 Canada 2021A000011124 Total, all violations [0]
#> 2 1998 Canada 2021A000011124 Total, all violations [0]
#> 3 1998 Canada 2021A000011124 Total, all violations [0]
#> 4 1998 Canada 2021A000011124 Total, all violations [0]
#> 5 1998 Canada 2021A000011124 Total, all violations [0]
#> 6 1998 Canada 2021A000011124 Total, all violations [0]
#> Statistics UOM UOM_ID
#> 1 Actual incidents Number 223
#> 2 Rate per 100,000 population Rate 257
#> 3 Percentage change in rate Percent 239
#> 4 Percentage contribution to the Crime Severity Index (CSI) Percent 239
#> 5 Unfounded incidents Number 223
#> 6 Percent unfounded Percent 239
#> SCALAR_FACTOR SCALAR_ID VECTOR COORDINATE VALUE STATUS SYMBOL
#> 1 units 0 v44348247 1.1.1 2688540.00 NA
#> 2 units 0 v44396346 1.1.2 8915.12 NA
#> 3 units 0 v44391402 1.1.3 NA .. NA
#> 4 units 0 v1545644596 1.1.17 100.00 NA
#> 5 units 0 v1000149311 1.1.15 NA .. NA
#> 6 units 0 v1000149312 1.1.16 NA .. NA
#> TERMINATED DECIMALS
#> 1 0
#> 2 2
#> 3 2
#> 4 2
#> 5 0
#> 6 2
# }