Skip to content

Commit

Permalink
harmonise functions names
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisManiere committed Feb 15, 2024
1 parent ea4d0f1 commit 5159c82
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 51 deletions.
10 changes: 5 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(button_label_with_popover)
export(cr_profile_empty)
export(cr_section_main)
export(data_get_axis)
Expand Down Expand Up @@ -44,17 +43,18 @@ export(map_wms_metric)
export(params_map_group)
export(params_metrics_choice)
export(params_unit_area)
export(params_url_remonterletemps)
export(params_wms)
export(run_app)
export(sld_get_quantile_colors)
export(sld_get_quantile_metric)
export(sld_get_style)
export(track_inputs)
export(track_session)
export(utile_get_metric_name_value)
export(utile_get_metric_type)
export(utile_normalize_string)
export(utils_button_label_with_popover)
export(utils_get_metric_name_value)
export(utils_get_metric_type)
export(utils_normalize_string)
export(utils_url_remonterletemps)
import(shiny)
importFrom(DBI,SQL)
importFrom(DBI,dbConnect)
Expand Down
1 change: 1 addition & 0 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ app_server <- function(input, output, session) {
mod_explore_server("explore_1", con)
mod_documentation_server("documentation_1")

# disconnect database when closing session
onStop(function() {
if (!is.null(con)) {
DBI::dbDisconnect(con)
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions R/fct_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#'
#' @examples
#' original_string <- "Thïs is à sâmplè strîng with spèciál chàracters!"
#' normalized_string <- utile_normalize_string(original_string)
#' normalized_string <- utils_normalize_string(original_string)
#' cat(normalized_string) # "thisisasamplestringwithspecialcharacters"
#'
#' @export
utile_normalize_string <- function(input_string) {
utils_normalize_string <- function(input_string) {
# Remove accents and diacritics
input_string <- chartr("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÝýÑñÇç",
"AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuYyNnCc",
Expand All @@ -40,10 +40,10 @@ utile_normalize_string <- function(input_string) {
#' @return A named character vector with metric type titles as names and metric type values as values.
#'
#' @examples
#' metric_types <- utile_get_metric_type(params_metrics_choice())
#' metric_types <- utils_get_metric_type(params_metrics_choice())
#'
#' @export
utile_get_metric_type <- function(input_list) {
utils_get_metric_type <- function(input_list) {
metric_type <- setNames(names(sapply(input_list, function(x) x$metric_type_title)), sapply(input_list, function(x) x$metric_type_title))
return(metric_type)
}
Expand All @@ -57,10 +57,10 @@ utile_get_metric_type <- function(input_list) {
#' @return A named character vector with all the metric names and values.
#'
#' @examples
#' metrics <- utile_get_metric_name_value("largeur")
#' metrics <- utils_get_metric_name_value("largeur")
#'
#' @export
utile_get_metric_name_value <- function(metric_type){
utils_get_metric_name_value <- function(metric_type){
metric_name <- sapply(params_metrics_choice()[[metric_type]]$metric_type_value, function(x) x$metric_title)
return(metric_name)
}
Expand All @@ -82,10 +82,10 @@ utile_get_metric_name_value <- function(metric_type){
#' metric type.
#'
#' @examples
#' metric_buttons <- button_label_with_popover("largeur")
#' metric_buttons <- utils_button_label_with_popover("largeur")
#'
#' @export
button_label_with_popover <- function(metric_type) {
utils_button_label_with_popover <- function(metric_type) {
metrics <-
names(params_metrics_choice()[[metric_type]]$metric_type_value)
buttons <- list()
Expand Down Expand Up @@ -133,8 +133,8 @@ button_label_with_popover <- function(metric_type) {
#' @export
#'
#' @examples
#' params_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12)
params_url_remonterletemps <- function(lng=6.869433,
#' utils_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12)
utils_url_remonterletemps <- function(lng=6.869433,
lat=45.923690,
zoom = 12){
url <- glue::glue("https://remonterletemps.ign.fr/comparer/basic?x={lng}&y={lat}&z={zoom}&layer1=GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2&layer2=ORTHOIMAGERY.ORTHOPHOTOS&mode=vSlider")
Expand Down
20 changes: 10 additions & 10 deletions R/mod_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod_explore_server <- function(id, con){

onclick(id = "logo_ign_remonterletemps", expr =
runjs(sprintf("window.open('%s', '_blank')",
params_url_remonterletemps(lng = input$exploremap_center$lng,
utils_url_remonterletemps(lng = input$exploremap_center$lng,
lat = input$exploremap_center$lat,
zoom = input$exploremap_zoom)))
)
Expand Down Expand Up @@ -406,7 +406,7 @@ mod_explore_server <- function(id, con){
r_val$selected_region_feature = data_get_region(region_click_id = r_val$region_click$id,
con = con)
# set region name to download
r_val$region_name = utile_normalize_string(r_val$selected_region_feature$lbregionhy)
r_val$region_name = utils_normalize_string(r_val$selected_region_feature$lbregionhy)
# get the axis in the region
r_val$network_region_axis = data_get_axis(selected_region_id = r_val$region_click$id,
con = con)
Expand Down Expand Up @@ -441,8 +441,8 @@ mod_explore_server <- function(id, con){
# build metric selectInput
r_val$ui_metric_type =
selectInput(ns("metric_type"), "Sélectionnez une métrique :",
choices = utile_get_metric_type(params_metrics_choice()),
selected = utile_get_metric_type(params_metrics_choice())[1])
choices = utils_get_metric_type(params_metrics_choice()),
selected = utils_get_metric_type(params_metrics_choice())[1])

# create download button
r_val$ui_download = downloadButton(
Expand Down Expand Up @@ -570,8 +570,8 @@ mod_explore_server <- function(id, con){
r_val$ui_metric = radioButtons(
inputId = ns("metric"),
label = NULL,
choiceNames = button_label_with_popover(input$metric_type),
choiceValues = as.list(names(utile_get_metric_name_value(input$metric_type))),
choiceNames = utils_button_label_with_popover(input$metric_type),
choiceValues = as.list(names(utils_get_metric_name_value(input$metric_type))),
selected = character(0)
)

Expand Down Expand Up @@ -653,8 +653,8 @@ mod_explore_server <- function(id, con){

# build input for profile metric type
r_val$ui_profile_metric_type = selectInput(ns("profile_metric_type"), "Ajoutez une métrique :",
choices = utile_get_metric_type(params_metrics_choice()),
selected = utile_get_metric_type(params_metrics_choice())[1])
choices = utils_get_metric_type(params_metrics_choice()),
selected = utils_get_metric_type(params_metrics_choice())[1])

# built ROE checkboxInput and input
r_val$ui_roe_profile = checkboxInput(ns("roe_profile"), label = "ROE", value = FALSE)
Expand Down Expand Up @@ -687,8 +687,8 @@ mod_explore_server <- function(id, con){
r_val$ui_profile_metric = radioButtons(
inputId = ns("profile_metric"),
label = NULL,
choiceNames = unname(utile_get_metric_name_value(input$profile_metric_type)),
choiceValues = names(utile_get_metric_name_value(input$profile_metric_type)),
choiceNames = unname(utils_get_metric_name_value(input$profile_metric_type)),
choiceValues = names(utils_get_metric_name_value(input$profile_metric_type)),
selected = character(0)
)

Expand Down
2 changes: 1 addition & 1 deletion man/track_inputs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/track_session.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/utile_get_metric_type.Rd → man/utils_get_metric_type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-fct_utils.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
test_that("params_url_remonterletemps works", {
url <- params_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12)
test_that("utils_url_remonterletemps works", {
url <- utils_url_remonterletemps(lng=6.869433, lat=45.923690, zoom = 12)
expect_true(inherits(url, "character"),
"character url loaded")
})

test_that("utile_normalize_string works", {
test_that("utils_normalize_string works", {
original_string <- "Thïs is à sâmplè strîng with spèciál chàracters!"
normalized_string <- utile_normalize_string(original_string)
normalized_string <- utils_normalize_string(original_string)
expect_true(normalized_string == "thisisasamplestringwithspecialcharacters")
})

0 comments on commit 5159c82

Please sign in to comment.