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

Merge branch 'removing_hash' into 'master'

Removing hash

See merge request !6
parents 55c11bf1 b39643a6
Pipeline #323985 passed with stage
in 12 seconds
^.*\.Rproj$
^\.Rproj\.user$
.dockerignore
.git
.gitattributes
.gitignore
.gitlab-ci.yml
.renku
.renkulfsignore
^.*\.Rproj$
^\.Rproj\.user$
data/*
demo.R
Dockerfile
environment.yml
example.Rmd
install.R
requirements.txt
data/*
.dockerignore
.renkulfsignore
.renku
example.html
example.Rmd
\ No newline at end of file
......@@ -10,13 +10,12 @@ Description: This package aims to simplify the access to the Swiss Federal Stati
Depends: R (>= 3.1.0)
License: GPL (>= 2)
Encoding: UTF-8
URL: https://renkulab.io/gitlab/pauline.maury-laribiere/metadata-auto-r-library
URL: https://renkulab.io/gitlab/dscc/metadata-auto-r-library
LazyData: true
Imports:
data.table,
dplyr,
glue,
hash,
httr,
jsonlite,
methods,
......
# Generated by roxygen2: do not edit by hand
export(get_codelist)
export(get_data_structure)
export(get_nomenclature_multiple_levels)
export(get_nomenclature_one_level)
importFrom(methods,new)
......
#' Get a codelist based on an identifier
#'
#' @param identifier the codelist's identifier
#' @param language string for language to return.
#' @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.
......@@ -41,7 +41,7 @@ get_codelist <- function(identifier,
#' (Code, Parent and Name in the selected language)
#' @export
get_nomenclature_one_level <- function(identifier,
filters = hash::hash(),
filters = list(),
level_number = 1,
language = "fr",
annotations = FALSE) {
......@@ -49,7 +49,7 @@ get_nomenclature_one_level <- function(identifier,
"language={language}",
"&level={level_number}",
"&annotations={tolower(annotations)}",
"&{hash_to_string(filters)}"
"&{list_to_string(filters)}"
)
print(parameters)
api <- api_class(
......@@ -76,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 = list(),
level_from = 1,
level_to = 2,
language = "fr",
......@@ -86,7 +86,7 @@ get_nomenclature_multiple_levels <- function(identifier,
"&levelFrom={level_from}",
"&levelTo={level_to}",
"&annotations={tolower(annotations)}",
"&{hash_to_string(filters)}"
"&{list_to_string(filters)}"
)
api <- api_class(
api_type = "nomenclature_multiple_levels",
......@@ -96,4 +96,3 @@ get_nomenclature_multiple_levels <- function(identifier,
)
res <- api$get_response()
}
......@@ -52,7 +52,7 @@ api_class <- setRefClass(
request_function(url)
},
get_url = function(id, export_format, version_format, language) {
url_mapping <- hash::hash(
url_mapping <- list(
"codelist" =
glue::glue("CodeLists/{id}/exports/{export_format}/{version_format}"),
"dcat_data_structure" =
......
......@@ -28,21 +28,21 @@ csv_request <- function(url) {
}
# Request function based on expected response
REQUEST_FUNCTION_MAPPING <- hash::hash(
REQUEST_FUNCTION_MAPPING <- list(
"SDMX-ML" = sdmx_request,
"JSON" = json_request,
"CSV" = csv_request
)
#' Transform a hash object into a string of parameters
#' hash::hash("a" = list("1"), "b" = list("2", "3"))
#' Transform a list into a string of parameters
#' list("a" = list("1"), "b" = list("2", "3"))
#' becomes "a=1&b=2&b=3"
#'
#' @param filters hash object
#' @param filters named list
#'
#' @return formatted string of parameters
hash_to_string <- function(filters) {
list_to_string <- function(filters) {
string <- ""
for (prop in ls(filters)) {
for (value in filters[[prop]]) {
......
......@@ -51,7 +51,7 @@ one_level_df <- get_nomenclature_one_level(identifier, level_number, filters, la
Parameters:
- identifier ("character"): nomenclature's identifier
- level_number ("numeric"): level to export
- filter (hash::hash): additionnal filters (hash)
- filter (list): additionnal filters in form of named list
- language ("character", default='fr'): response data's language
Available are 'fr', 'de', 'it', 'en'.
- annotations (bool, default=FALSE): flag to include annotations
......@@ -69,7 +69,7 @@ multiple_levels_df = get_nomenclature_multiple_levels(identifier, level_from, le
- identifier ("character"): nomenclature's identifier
- level_from ("numeric"): the 1st level to include
- level_to ("numeric"): the last level to include
- filter (hash::hash): additionnal filters
- filter (list): additionnal filters in form of named list
- language ("character", default='fr'): response data's language
Available are 'fr', 'de', 'it', 'en'.
- annotations (bool, default=FALSE): flag to include annotations
......
# When the package will be finished, install via CRAN
# install.packages("fso.metadata")
# library("fso.metadata")
# Get a codelist
# In german
codelist <- get_codelist(identifier='CL_NOGA_SECTION', language='de')
head(codelist$label.de)
head(codelist$id)
# In french
codelist <- get_codelist(identifier='CL_NOGA_SECTION', language='fr')
head(codelist$label.fr)
head(codelist$id)
## Get a nomenclature of one level
# French 2 levels
nomenclature_fr <- get_nomenclature_one_level(
identifier='HCL_CH_ISCO_19_PROF', level_number=2, language='fr'
)
head(nomenclature_fr, 10)
# German 3 levels
nomenclature_de <- get_nomenclature_one_level(
identifier='HCL_CH_ISCO_19_PROF', level_number=3, language='de'
)
head(nomenclature_de, 10)
## Get a nomenclature of multiple levels
# French
multi_nomenclature_fr <- get_nomenclature_multiple_levels(
identifier='HCL_CH_ISCO_19_PROF',
level_from=2,
level_to=5,
language='fr'
)
head(multi_nomenclature_fr, 10)
# German
multi_nomenclature_de <- get_nomenclature_multiple_levels(
identifier='HCL_CH_ISCO_19_PROF',
level_from=1,
level_to=3,
language='de'
)
head(multi_nomenclature_de, 10)
......@@ -15,7 +15,7 @@ get_codelist(
\arguments{
\item{identifier}{the codelist's identifier}
\item{language}{string for language to return.
\item{language}{string for language to return.
Available are 'fr', 'de', 'it', 'en'.}
\item{export_format}{the export's format
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/api_call.R
\name{get_data_structure}
\alias{get_data_structure}
\title{Get the data structure}
\usage{
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'}
}
\value{
data structure of dcat
}
\description{
Get the data structure
}
......@@ -6,7 +6,7 @@
\usage{
get_nomenclature_multiple_levels(
identifier,
filters = hash::hash(),
filters = list(),
level_from = 1,
level_to = 2,
language = "fr",
......
......@@ -6,7 +6,7 @@
\usage{
get_nomenclature_one_level(
identifier,
filters = hash::hash(),
filters = list(),
level_number = 1,
language = "fr",
annotations = FALSE
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/format_request.R
\name{hash_to_string}
\alias{hash_to_string}
\title{Transform a hash object into a string of parameters
hash::hash("a" = list("1"), "b" = list("2", "3"))
\name{list_to_string}
\alias{list_to_string}
\title{Transform a list into a string of parameters
list("a" = list("1"), "b" = list("2", "3"))
becomes "a=1&b=2&b=3"}
\usage{
hash_to_string(filters)
list_to_string(filters)
}
\arguments{
\item{filters}{hash object}
\item{filters}{named list}
}
\value{
formatted string of parameters
}
\description{
Transform a hash object into a string of parameters
hash::hash("a" = list("1"), "b" = list("2", "3"))
Transform a list into a string of parameters
list("a" = list("1"), "b" = list("2", "3"))
becomes "a=1&b=2&b=3"
}
testthat::test_that("hash_to_string", {
testthat::test_that("list_to_string", {
expect_equal(
hash_to_string(hash::hash("a" = list("1"), "b" = list("2", "3"))),
list_to_string(list("a" = list("1"), "b" = list("2", "3"))),
"a=1&b=2&b=3"
)
})
......
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