Skip to content
Commits on Source (4)
......@@ -24,7 +24,7 @@ json_request <- function(url) {
#'
#' @return dataframe response
csv_request <- function(url) {
read.csv(url)
read.csv(url, encoding = "UTF-8")
}
# Request function based on expected response
......
......@@ -11,11 +11,7 @@ This public library is made available for the internal FSO staff, the federal ad
You can install the library with
```
install.packages("remotes")
remotes::install_gitlab("d6538/fso-metadata-r")
```
or
```
devtools::install_url("https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/archive/v003/metadata-auto-r-library-v003.tar.gz")
remotes::install_gitlab("dscc/fso-metadata-r")
```
then at the beginning of your R script, you will need to
......@@ -116,4 +112,6 @@ All the APIs made available in this library are also documented in Swagger UI sh
Examples for each API are provided in the [R Markdown](https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/blob/master/example.Rmd).
A documentation page is also available [here](https://d6538.gitlab.io/fso-metadata-r/).
Practical [demo](https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/blob/master/demo.R).
A documentation page is also available [here](https://dscc.gitlab.io/fso-metadata-r/).
install.packages("remotes")
remotes::install_gitlab("dscc/fso-metadata-r")
### Preparation ###
devtools::install_url("https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/archive/v002/metadata-auto-r-library-v002.tar.gz")
library(fso.metadata)
library(ggplot2)
library(tidyverse)
### 1. Get a codelist ###
# All languages
codelist <- get_codelist(identifier = "CL_NOGA_SECTION")
codelist <- get_codelist(identifier = "CL_NOGA_DIVISION")
head(codelist, 3)
### 1. Get a codelist ###
# In french
codelist_fr <- get_codelist(identifier = "CL_NOGA_SECTION", language = "fr")
head(codelist_fr, 3)
### 2. Get a nomenclature of one level ###
# All language: Level 1
nomenclature <- get_nomenclature_one_level(
identifier = "HCL_CH_ISCO_19_PROF",
level_number = 2
)
head(nomenclature, 3)
# French: Level 2
nomenclature_fr <- get_nomenclature_one_level(
identifier = "HCL_CH_ISCO_19_PROF",
level_number = 1,
language = "fr"
)
head(nomenclature_fr, 5)
# In german
codelist_de <- get_codelist(identifier = "CL_NOGA_SECTION", language = "de")
head(codelist_de, 3)
### 3. Get a nomenclature of multiple levels ###
# French
multi_nomenclature_fr <- get_nomenclature_multiple_levels(
### 2. Get a nomenclature of multiple levels ###
# In italian
multi_nomenclature_it <- get_nomenclature_multiple_levels(
identifier = "HCL_CH_ISCO_19_PROF",
level_from = 1,
level_to = 6,
language = "fr"
language = "it"
)
head(multi_nomenclature_fr, 10)
head(multi_nomenclature_it, 8)
### 4. Concrete example from Mr. van Nieuwkoop with Noga Data
system("git lfs pull data/pkagg.Rdata")
### 3. Concrete example from Mr. van Nieuwkoop with Noga Data
library(ggplot2)
library(tidyverse)
load("data/pkagg.Rdata")
head(pk_agg$A88)
# Load the production account data for the agriculture divisions
load("data/pk_agr.Rdata")
pk_agr <- rename(pk_agr, Component = Komponent, Year = Jahr)
head(pk_agr)
noga2 <- as_tibble(get_codelist(identifier = "CL_NOGA_DIVISION", language = "it"))
# Load the descriptions of the NOGA divisions
noga2 <- as_tibble(
get_codelist(identifier='CL_NOGA_DIVISION', language='fr')
)
names(noga2) <- c("id", "label", "name")
head(noga2)
# Get the completely disaggregated production accounts
# and join them with the noga2 descriptions
a88 <- pk_agg$A88 %>%
left_join(noga2, by = c("Code" = "id"))
head(a88)
# Filter and prepare data
a88_filtered <- a88 %>%
select(-Beschreibung, -name) %>%
# Join the production account data with the noga2 descriptions
pk <- pk_agr %>%
left_join(noga2, by = c("Code" = "id")) %>%
select(-name) %>%
relocate(label, .after = Code) %>%
rename(Department = label, Year = Jahr, Component = Komponent) %>%
select(Code, Department, Component, Year, Nominal) %>%
filter(Nominal > 0) %>%
filter(!is.na(Department)) %>%
# keep
filter(Code %in% c("01", "02", "03")) # keep first 3 department
rename(Department = label)
head(pk)
# Plot the intermediate consumption (CI), the value added (VA), and the
# production value (VP) for the section A (agriculture)
ggplot(a88_filtered, aes(Year, Nominal, color = Component)) +
pk %>%
select(Code, Department, Component, Year, Nominal) %>%
filter(Nominal > 0 & !is.na(Department)) %>%
ggplot(aes(Year, Nominal, color = Component)) +
geom_line() +
ylab("in Mio. CHF") +
facet_wrap(~Department, scales = "free")
facet_wrap(~Department, scales = "free")
plot_agriculture <- function(pk_agr, language) {
# Load the descriptions of the NOGA divisions
noga2 <- as_tibble(
get_codelist(
identifier='CL_NOGA_DIVISION',
language=language,
environment='ABN') # for the demo, only available within network
)
names(noga2) <- c("id", "label", "name")
# Join the production account data with the noga2 descriptions
pk <- pk_agr %>%
left_join(noga2, by = c("Code" = "id")) %>%
select(-name) %>%
relocate(label, .after = Code) %>%
rename(Department = label)
# Plot the intermediate consumption (CI), the value added (VA), and the
# production value (VP) for the section A (agriculture)
pk %>%
select(Code, Department, Component, Year, Nominal) %>%
filter(Nominal > 0 & !is.na(Department)) %>%
ggplot(aes(Year, Nominal, color = Component)) +
geom_line() +
ylab("in Mio. CHF") +
facet_wrap(~Department, scales = "free")
}
plot_agriculture(pk_agr, language='fr')
plot_agriculture(pk_agr, language='de')
plot_agriculture(pk_agr, language='it')
plot_agriculture(pk_agr, language='en')
......@@ -14,7 +14,8 @@ knitr::opts_chunk$set(echo = TRUE)
You can install the library with
```{r install}
devtools::install_url("https://renkulab.io/gitlab/dscc/metadata-auto-r-library/-/archive/v002/metadata-auto-r-library-v002.tar.gz")
install.packages("remotes")
remotes::install_gitlab("dscc/fso-metadata-r")
```
then at the beginning of your R script, you will need to
......
This diff is collapsed.
......@@ -2,5 +2,5 @@ pandoc: 2.14.1
pkgdown: 1.6.1
pkgdown_sha: ~
articles: {}
last_built: 2022-03-07T16:49Z
last_built: 2022-03-10T09:47Z