source("R/setup.R")$value
if (!sc_key_exists()) knitr::opts_chunk$set(eval = FALSE)
In the following example, a table will be exported from STATcube into an R session. This process involves four steps
*.json
).json
file to the API using sc_table()
.data.frame
It is assumed that you already provided your API key as described in the r ticle("sc_key")
.
Use the graphical user interface of STATcube to create a table. Visit STATcube and select a database. This will open the table view where you can create a table. See the STATcube documentation for details.
Choose "Open Data API Query (.json)" in the download options. This will save a json file on your local file system.
knitr::include_graphics("img/download_json.png")
It might be the case that this download option is not listed as a download format. This means that the current user is not permitted to use the API.
Provide the path to the downloaded json file as a string in sc_table()
.
library(STATcubeR) my_table <- sc_table(json = "path/to/api_request.json")
This will send the json-request to the [/table
endpoint] of the API and return an object of class sc_table
.
We will demonstrate this with an example json via sc_example()
.
(json_path <- sc_example("population_timeseries.json")) ## [1] "~/R/3.6/STATcubeR/json_examples/population_timeseries.json" my_table <- sc_table(json_path)
Printing the object my_table
will summarize the data contained in the response.
my_table
The return value of sc_table()
can be converted into a data.frame
with as.data.frame()
.
as.data.frame(my_table)
This will produce a data.frame
, which contains a column for each classification field of the table.
Furthermore, one column will be present for each measure.
In other words, the data uses a long format.
If you prefer to use codes rather than labels, use my_table$data
instead.
my_table$data
This article used a dataset about the Austrian population via sc_example()
.
r STATcubeR
contains more example jsons to get started.
The datasets can be listed with sc_examples_list()
.
sc_example("accomodation.json") %>% sc_table()
sc_example("economic_atlas.json") %>% sc_table()
sc_example("foreign_trade.json") %>% sc_table()
sc_example("gross_regional_product.json") %>% sc_table()
sc_example("labor_force_survey.json") %>% sc_table()
```{r, eval = FALSE sc_example("agriculture_prices.json") %>% sc_table()
### monitor.statistik.at ```r sc_example("economic_trend_monitor.json") %>% sc_table()
The language which is used for labeling can be changed via the language
parameter of sc_table()
.
sc_example("accomodation.json") %>% sc_table("de")
sc_example("economic_atlas.json") %>% sc_table("de")
sc_example("foreign_trade.json") %>% sc_table("de")
sc_example("gross_regional_product.json") %>% sc_table("de")
sc_example("labor_force_survey.json") %>% sc_table("de")
sc_example("agriculture_prices.json") %>% sc_table("de")
sc_example("economic_trend_monitor.json") %>% sc_table("de")
r ticle("sc_data")
.sc_tabulate()
provides a more flexible way of turning STATcube tables into
data.frame
s. See the r ticle("sc_tabulate")
for more details.r ticle("sc_table_saved")
shows an alternative way of importing tables.r ticle("sc_schema")
or the r ticle("sc_info")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.