PX-WEB API Interface for R

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

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:

install.packages("devtools")
devtools::install_github("pxweb","rOpenGov")

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.

Listing available pxweb apis

To list the available apis in the package, use api_catalogue().

library(pxweb)
api_catalogue()[1:2]
## [[1]]
## Api: api.scb.se ('scb')
##      Statistics Sweden 
## Version(s)   : v1 
## Language(s)  : en, sv 
## Limit(s)     : 30 calls per 10 sec.
##                1e+05  values per call.
## Url template :
##  http://api.scb.se/OV0104/[version]/doris/[lang] 
## 
## [[2]]
## Api: pxnet2.stat.fi ('statfi')
##      Statistics Finland 
## Version(s)   : v1 
## Language(s)  : fi 
## Limit(s)     : 30 calls per 10 sec.
##                1e+05  values per call.
## Url template :
##  http://pxnet2.stat.fi/PXWeb/api/[version]/[lang]

Fetching data from PX-WEB API:

Interactive API query (not run):

# 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")

Create a new PX-WEB API:

If a pxweb api is missing in the api catalogue, you can just add the api yourself in the following way.

# Create a pxweb api object
my_api <- 
  pxweb_api$new(api = "foo.bar",
                url = "http://api.foo.bar/[lang]/[version]",
                description = "My own pxweb api",
                languages = "en", # Languages
                versions = "v1", # Versions         
                calls_per_period = 1,
                period_in_seconds = 2, 
                max_values_to_download = 10)

# Test that the api works
my_api$test_api()

# Add the api to the api catalogue
my_api$write_to_catalogue()

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 version 3.1.1 (2014-07-10)
## Platform: x86_64-apple-darwin13.1.0 (64-bit)
## 
## locale:
## [1] sv_SE.UTF-8/sv_SE.UTF-8/sv_SE.UTF-8/C/sv_SE.UTF-8/sv_SE.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] pxweb_0.5.3
## 
## loaded via a namespace (and not attached):
##  [1] data.table_1.9.2 digest_0.6.4     evaluate_0.5.5   formatR_0.10    
##  [5] htmltools_0.2.4  httr_0.5         jsonlite_0.9.8   knitr_1.6       
##  [9] plyr_1.8.1       Rcpp_0.11.1      RCurl_1.95-4.1   reshape2_1.4    
## [13] RJSONIO_1.2-0.2  rmarkdown_0.2.64 stringr_0.6.2    tools_3.1.1     
## [17] yaml_2.1.13