Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
DSCC
FSO Metadata Auto R
Commits
219eac0a
Commit
219eac0a
authored
Mar 01, 2022
by
Pauline Maury Laribière
Browse files
adding demo for health.renku and removing all hashes
parent
baf86817
Pipeline
#323979
passed with stage
in 3 minutes and 4 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.Rbuildignore
View file @
219eac0a
...
...
@@ -11,5 +11,6 @@ data/*
.dockerignore
.renkulfsignore
.renku
demo.R
example.html
example.Rmd
\ No newline at end of file
DESCRIPTION
View file @
219eac0a
...
...
@@ -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,
...
...
NAMESPACE
View file @
219eac0a
# 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)
...
...
R/api_call.R
View file @
219eac0a
...
...
@@ -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"
,
...
...
R/api_class.R
View file @
219eac0a
...
...
@@ -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"
=
...
...
@@ -66,3 +66,4 @@ api_class <- setRefClass(
}
)
)
R/format_request.R
View file @
219eac0a
...
...
@@ -39,7 +39,7 @@ REQUEST_FUNCTION_MAPPING <- list(
#' list("a" = list("1"), "b" = list("2", "3"))
#' becomes "a=1&b=2&b=3"
#'
#' @param filters
hash objec
t
#' @param filters
named lis
t
#'
#' @return formatted string of parameters
list_to_string
<-
function
(
filters
)
{
...
...
README.md
View file @
219eac0a
...
...
@@ -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
...
...
demo.R
0 → 100644
View file @
219eac0a
# 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
)
man/get_data_structure.Rd
deleted
100644 → 0
View file @
baf86817
% 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
}
man/get_nomenclature_multiple_levels.Rd
View file @
219eac0a
...
...
@@ -6,7 +6,7 @@
\usage{
get_nomenclature_multiple_levels(
identifier,
filters =
hash::hash
(),
filters =
list
(),
level_from = 1,
level_to = 2,
language = "fr",
...
...
man/get_nomenclature_one_level.Rd
View file @
219eac0a
...
...
@@ -6,7 +6,7 @@
\usage{
get_nomenclature_one_level(
identifier,
filters =
hash::hash
(),
filters =
list
(),
level_number = 1,
language = "fr",
annotations = FALSE
...
...
man/
hash
_to_string.Rd
→
man/
list
_to_string.Rd
View file @
219eac0a
% 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 objec
t 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
lis
t 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 objec
t}
\item{filters}{
named lis
t}
}
\value{
formatted string of parameters
}
\description{
Transform a
hash objec
t into a string of parameters
hash::hash
("a" = list("1"), "b" = list("2", "3"))
Transform a
lis
t into a string of parameters
list
("a" = list("1"), "b" = list("2", "3"))
becomes "a=1&b=2&b=3"
}
tests/testthat.R
View file @
219eac0a
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"
)
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment