PX-WEB API Interface for R

Mans Magnusson and Leo Lahti

2016-12-05

This R package provides tools to access PX-WEB API. Your contributions and bug reports and other feedback are welcome!

More information on the PX-Web/PC-Axis API can be found here.

Table of contents

Installation (Installation)
Examples (Examples)

Available data sources and tools

A number of organizations use to distribute hierarchical data. You can browse the available data sets at:

Installation

Install the stable release version in R:

install.packages("pxweb")

Install the latest version from github:

library("devtools")
devtools::install_github("ropengov/pxweb")

Test the installation by loading the library:

library(pxweb)

A tutorial is included with the package with:

vignette(topic="pxweb")

Other issues

We also recommend setting the UTF-8 encoding:

Sys.setlocale(locale="UTF-8") 

Examples

Some examples on using the R tools to fetch px-web API data.

Fetching data from PX-WEB API:

Interactive API query:

# Navigate through all pxweb api:s installed.
d <- interactive_pxweb()

# Get data from SCB (Statistics Sweden)
d <- interactive_pxweb(api = "api.scb.se")

# Fetching data from the swedish SCB (Statistics Sweden) pxweb API:
d <- interactive_pxweb(api = "api.scb.se", version = "v1", lang = "sv")

# Fetching data from statfi (Statistics Finland)
d <- interactive_pxweb(api = "pxwebapi2.stat.fi")

Example of download data from the Statistics Sweden API using get_pxweb_data():

pxweb_test_data <- 
  get_pxweb_data(url = "http://api.scb.se/OV0104/v1/doris/sv/ssd/PR/PR0101/PR0101E/Basbeloppet", 
                 dims = list(ContentsCode = c('PR0101A1'), 
                             Tid = c('*')),
                 clean = FALSE)

Licensing and Citations

This work can be freely used, modified and distributed under the open license specified in the DESCRIPTION file.

Kindly cite the work as follows

citation("pxweb")
## 
## Kindly cite the pxweb R package as follows:
## 
##   (C) Mans Magnusson, Leo Lahti and Love Hansson (rOpenGov 2014).
##   pxweb: R tools for PX-WEB API.  URL:
##   http://github.com/ropengov/pxweb
## 
## A BibTeX entry for LaTeX users is
## 
##   @Misc{,
##     title = {pxweb: R tools for PX-WEB API},
##     author = {Mans Magnusson and Leo Lahti and Love Hansson},
##     year = {2014},
##   }

About the API

The data in this RESTful API consists of a metadata part and a data part. Metadata is structured in a hierarchical node tree, where each node contains information about subnodes that are below it in the tree or, if the nodes is at the bottom of the tree structure, the data referenced by the node as well as what dimensions are available for the data at that subnode.

Session info

This vignette was created with

sessionInfo()
## R Under development (unstable) (2016-12-05 r71733)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Debian GNU/Linux stretch/sid
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] pxweb_0.6.3
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.8       digest_0.6.10     rprojroot_1.1    
##  [4] plyr_1.8.4        R6_2.2.0          jsonlite_1.1     
##  [7] backports_1.0.4   magrittr_1.5      evaluate_0.10    
## [10] httr_1.2.1        stringi_1.1.2     curl_2.3         
## [13] data.table_1.10.0 rmarkdown_1.2     RJSONIO_1.3-0    
## [16] tools_3.4.0       stringr_1.1.0     yaml_2.1.14      
## [19] compiler_3.4.0    htmltools_0.3.5   knitr_1.15.1