Commit e9c537c8 authored by Pauline Maury Laribière's avatar Pauline Maury Laribière
Browse files

cleaning code and moving files

parent 1290f466
Pipeline #323955 passed with stage
in 3 minutes and 14 seconds
......@@ -10,4 +10,6 @@ requirements.txt
data/*
.dockerignore
.renkulfsignore
.renku
\ No newline at end of file
.renku
example.html
example.Rmd
\ No newline at end of file
#' Get a codelist based on an identifier
#'
#' @param identifier the codelist's identifier
#' @param language string for language to return.
#' Available are 'fr', 'de', 'it', 'en'.
#' @param export_format the export's format
#' Available are CSV, XLSX, SDMX-ML or JSON.
#' @param version_format the export format's version
......@@ -20,25 +22,9 @@ get_codelist <- function(identifier,
parameters = glue::glue("annotations={tolower(annotations)}"),
id = identifier
)
dplyr::select(api$get_response(), contains(language) | matches("id"))
}
#' Get the data structure
#'
#' @param identifier the dataset's identifier
#' @param language the language of the response data
#' Available are 'fr', 'de', 'it', 'en'.
#'
#' @return data structure
#' @export
get_data_structure <- function(identifier, language = "fr") {
api <- api_class(
api_type = "dcat_data_structure",
id = identifier,
language = language
dplyr::select(
api$get_response(), dplyr::contains(language) | dplyr::matches("id")
)
api$get_response()
}
......@@ -55,7 +41,7 @@ get_data_structure <- function(identifier, language = "fr") {
#' (Code, Parent and Name in the selected language)
#' @export
get_nomenclature_one_level <- function(identifier,
filters=hash::hash(),
filters = hash::hash(),
level_number = 1,
language = "fr",
annotations = FALSE) {
......@@ -90,7 +76,7 @@ get_nomenclature_one_level <- function(identifier,
#' from `level_from` to `level_to` codes
#' @export
get_nomenclature_multiple_levels <- function(identifier,
filters=hash::hash(),
filters = hash::hash(),
level_from = 1,
level_to = 2,
language = "fr",
......@@ -110,3 +96,4 @@ get_nomenclature_multiple_levels <- function(identifier,
)
res <- api$get_response()
}
......@@ -14,12 +14,12 @@ knitr::opts_chunk$set(echo = TRUE)
You can install the library with
```{r install}
install.packages("fso.metadata")
devtools::install_github("SDCC/metadata-auto-r-library")
```
then at the beginning of your R script, you will need to
```{r library}
library("fso.metadata")
library("metadata-auto-r-library")
```
......@@ -32,12 +32,6 @@ get_codelist(identifier='CL_NOGA_SECTION', language='de')
```
## Data Structure
```{r , echo=FALSE}
get_data_structure(identifier='HCL_NOGA', language='it')
```
## Nomenclature
```{r , echo=FALSE}
my_filters <- hash::hash(
......
This diff is collapsed.
......@@ -10,6 +10,7 @@ library(httr)
library(jsonlite)
library(rsdmx)
# pkgload::load_all('fso.metadata')
# styler::style_pkg('fso.metadata')
# testthat::test_file("fso.metadata/tests/testthat.R")
\ No newline at end of file
# pkgload::load_all('.')
# styler::style_pkg('.')
# devtools::check('.')
# testthat::test_file("tests/testthat.R")
\ No newline at end of file
......@@ -20,11 +20,11 @@ Available are CSV, XLSX, SDMX-ML and JSON}
\item{\code{id}}{character. The identifier or id of the request's object}
\item{\code{language}}{character (default = "en"). The language of the response data.
\item{\code{language}}{character (default = "en"). Language of the response data.
Available are 'fr', 'de', 'it', 'en'}
\item{\code{version_format}}{numeric (default = 2.1). The export format's version
(2.0 or 2.1 when format is SDMX-ML)
(2.0 or 2.1 when format is SDMX-ML)
(for 'codelist')}
\item{\code{api_url}}{character. The url to make the request to.}
......
......@@ -6,6 +6,7 @@
\usage{
get_codelist(
identifier,
language = "fr",
export_format = "SDMX-ML",
version_format = 2.1,
annotations = FALSE
......@@ -14,6 +15,9 @@ get_codelist(
\arguments{
\item{identifier}{the codelist's identifier}
\item{language}{string for language to return.
Available are 'fr', 'de', 'it', 'en'.}
\item{export_format}{the export's format
Available are CSV, XLSX, SDMX-ML or JSON.}
......
......@@ -4,16 +4,16 @@
\alias{get_data_structure}
\title{Get the data structure}
\usage{
get_data_structure(identifier, language = "en")
get_data_structure(identifier, language)
}
\arguments{
\item{identifier}{the dataset's identifier}
\item{language}{the language of the response data
Available are 'fr', 'de', 'it', 'en'.}
Available are 'fr', 'de', 'it', 'en'}
}
\value{
data structure
data structure of dcat
}
\description{
Get the data structure
......
......@@ -6,10 +6,10 @@
\usage{
get_nomenclature_multiple_levels(
identifier,
filters,
filters = hash::hash(),
level_from = 1,
level_to = 2,
language = "en",
language = "fr",
annotations = FALSE
)
}
......
......@@ -6,9 +6,9 @@
\usage{
get_nomenclature_one_level(
identifier,
filters,
filters = hash::hash(),
level_number = 1,
language = "en",
language = "fr",
annotations = FALSE
)
}
......
test_that("hash_to_string", {
testthat::test_that("hash_to_string", {
expect_equal(
hash_to_string(hash::hash("a" = list("1"), "b" = list("2", "3"))),
hash_to_string(hash::hash("a" = list("1"), "b" = list("2", "3"))),
"a=1&b=2&b=3"
)
})
test_that("nomenclature_one_level", {
testthat::test_that("nomenclature_one_level", {
expect_equal(
names(get_nomenclature_one_level(
identifier='HCL_CH_ISCO_19_PROF',
level_number=2,
language='fr')
),
identifier = "HCL_CH_ISCO_19_PROF",
level_number = 2,
language = "fr"
)),
c("Code", "Parent", "Name_fr")
)
})
test_that("nomenclature_multiple_levels", {
testthat::test_that("nomenclature_multiple_levels", {
expect_equal(
names(
get_nomenclature_multiple_levels(
identifier='HCL_CH_ISCO_19_PROF',
level_from=1,
level_to=6,
language='en'
identifier = "HCL_CH_ISCO_19_PROF",
level_from = 1,
level_to = 6,
language = "en"
)
),
),
c(
"Major_groups",
"Sub.major_groups",
"Major_groups",
"Sub.major_groups",
"Minor_groups",
"Unit_groups",
"Type",
"Occupations",
"Occupations",
"Code",
"Name_en"
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment