| Title: | Support for Geography Packages |
|---|---|
| Description: | Support functions for the GeoVerse packages. |
| Authors: | Pascal Burkhard [aut, cre] (ORCID: <https://orcid.org/0009-0001-5504-5084>) |
| Maintainer: | Pascal Burkhard <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.0.9000 |
| Built: | 2026-10-30 21:22:11 UTC |
| Source: | https://github.com/Nenuial/geotools |
Provide custom countrycode function
gtl_admin_code(..., country = c("China", "Switzerland", "Russia"))gtl_admin_code(..., country = c("China", "Switzerland", "Russia"))
... |
Arguments passed on to
|
country |
Select the custom dictionary, currently one of China, Switzerland or Russia |
A vector with the desired output
tibble::tribble( ~canton, ~population, "Neuchâtel", 176496, "Vaud", 805098, "Genève", 504128 ) -> population population |> dplyr::mutate(iso = gtl_admin_code( sourcevar = canton, origin = "canton.name.regex", destination = "iso", origin_regex = TRUE, country = "Switzerland" ))tibble::tribble( ~canton, ~population, "Neuchâtel", 176496, "Vaud", 805098, "Genève", 504128 ) -> population population |> dplyr::mutate(iso = gtl_admin_code( sourcevar = canton, origin = "canton.name.regex", destination = "iso", origin_regex = TRUE, country = "Switzerland" ))
Check API connexion
gtl_chk_api_call(call)gtl_chk_api_call(call)
call |
An API url |
Returns an error if the API call fails
Function to check if the IDB API key is correctly set.
gtl_chk_idb_api_key()gtl_chk_idb_api_key()
Returns an error if the IDB API key is not properly set
# Not run: fails if the IDB API key isn't set gtl_chk_idb_api_key()# Not run: fails if the IDB API key isn't set gtl_chk_idb_api_key()
Function to check if the NOAA API key is correctly set.
gtl_chk_rnoaa_api_key()gtl_chk_rnoaa_api_key()
Returns an error if the NOAA API key is not properly set
# Not run: fails if the NOAA API key isn't set gtl_chk_rnoaa_api_key()# Not run: fails if the NOAA API key isn't set gtl_chk_rnoaa_api_key()
This function returns a list of World Bank countries for a choice selector in a Shiny app.
gtl_country_list_noaa()gtl_country_list_noaa()
# Not run: need the NCDC city database gtl_country_list_noaa()# Not run: need the NCDC city database gtl_country_list_noaa()
This function returns a list of World Bank countries for a choice selector in a Shiny app.
gtl_country_list_wb()gtl_country_list_wb()
gtl_country_list_wb()gtl_country_list_wb()
A function that returns the corresponding CRS for different codes.
gtl_crs_proj(code)gtl_crs_proj(code)
code |
A string with the CRS identifier |
The current list of available codes is:
eqearth
equirec
gallpeters
goode
hobodyer
mercator
robinson
wintri
A CRS object
gtl_crs_proj("eqearth") gtl_crs_proj("robinson")gtl_crs_proj("eqearth") gtl_crs_proj("robinson")
A function that returns an ideal CRS for a given country.
gtl_crs_regional(country)gtl_crs_regional(country)
country |
A string with the country name |
The current list of possible countries:
Russia
A CRS object
gtl_crs_regional("Russia")gtl_crs_regional("Russia")
Download JSON response from API
gtl_dwnl_api_json(call)gtl_dwnl_api_json(call)
call |
An API url |
JSON body
gtl_dwnl_api_json("https://dummyjson.com/products/1")gtl_dwnl_api_json("https://dummyjson.com/products/1")
Puts a non-breaking space (U+00A0) before ; : ! ? » and %, and after
«, in place of a plain space, so that these signs never start a line.
The non-breaking space is in Latin-1, so every pdf device can draw it.
gtl_translate_enfr() applies it to the French strings. Anything but text
is returned unchanged.
gtl_fr_typo(x)gtl_fr_typo(x)
x |
A character vector of French text |
The text with non-breaking spaces
gtl_fr_typo("Source : OFS ; Donn\u00e9es : 2024, soit 12 %")gtl_fr_typo("Source : OFS ; Donn\u00e9es : 2024, soit 12 %")
This function formats a date in a long format (see return value). The format
takes the current language setting into account (see gtl_opt_set_i18n()).
gtl_full_date(date)gtl_full_date(date)
date |
A date in YYYY-MM-DD format |
A formated day month year (%d %B %Y) date
# Set en english locale gtl_opt_set_i18n("en_US") gtl_full_date("2020-02-20") # Set a french locale gtl_opt_set_i18n("fr_FR") gtl_full_date("2020-02-20")# Set en english locale gtl_opt_set_i18n("en_US") gtl_full_date("2020-02-20") # Set a french locale gtl_opt_set_i18n("fr_FR") gtl_full_date("2020-02-20")
World Tissot Matrix
gtl_gis_tissot_indicatrix()gtl_gis_tissot_indicatrix()
A simple feature layer
gtl_gis_tissot_indicatrix()gtl_gis_tissot_indicatrix()
Return a list of color breaks for Higchart maps
gtl_hc_color_axis(breaks, palette)gtl_hc_color_axis(breaks, palette)
breaks |
The data with the breaks (using chopped data with |
palette |
A color palette that can take a numeric argument |
A list of lists to use in colorAxis' dataClasses argument
data <- seq(1, 20) data_cut <- santoku::chop(data, breaks = c(5, 10, 15)) gtl_hc_color_axis(data_cut, rainbow)data <- seq(1, 20) data_cut <- santoku::chop(data, breaks = c(5, 10, 15)) gtl_hc_color_axis(data_cut, rainbow)
Return a list of color breaks for Higchart maps
gtl_hc_discrete_color_axis(breaks, palette)gtl_hc_discrete_color_axis(breaks, palette)
breaks |
The data with the breaks (factors !) |
palette |
A color palette that can take a numeric argument |
A list of lists to use in colorAxis' dataClasses argument
mapView options for highcharter objects
gtl_hc_map_view(hc, ...)gtl_hc_map_view(hc, ...)
hc |
A |
... |
Options as defined in https://api.highcharts.com/highmaps/mapView. |
This function returns a dataframe with the 47 countries for which
the Human Mortality Database provides
data. For each country there is a name and a code.
gtl_hmd_codes()gtl_hmd_codes()
A dataframe with 2 columns and 47 rows
gtl_hmd_codes()gtl_hmd_codes()
The Köppen-Geiger classification as in Beck et al. (2018, 2023) after Peel
et al. (2007), the same as the GeoResources climate diagrams: B (arid) is
tested first, summer is the warmer half-year (April–September or
October–March), and C and D are separated at 0 °C (cd = -3 for Köppen's
original -3 °C).
gtl_koppen_code(temp, prec, lat = NULL, cd = 0)gtl_koppen_code(temp, prec, lat = NULL, cd = 0)
temp |
A vector with temperatures in degree Celsius for each month |
prec |
A vector with precipitations in millimeters for each month |
lat |
Unused: the summer half-year is found from the temperatures. Kept for compatibility. |
cd |
The temperature of the coldest month separating C from D climates |
A string with the Köppen climate determination
# Based on climate data for Geneva gtl_koppen_code( temp = c(2.1, 3, 6.8, 10.4, 14.8, 18.4, 20.5, 20.2, 15.8, 11.5, 6, 2.7), prec = c(70.8, 60.6, 56.9, 69, 75.7, 78.8, 83.2, 81.4, 94.9, 97.6, 90.3, 85.2) )# Based on climate data for Geneva gtl_koppen_code( temp = c(2.1, 3, 6.8, 10.4, 14.8, 18.4, 20.5, 20.2, 15.8, 11.5, 6, 2.7), prec = c(70.8, 60.6, 56.9, 69, 75.7, 78.8, 83.2, 81.4, 94.9, 97.6, 90.3, 85.2) )
Label functions for ggplot2 scales (or for any vector of numbers) that
follow the current language setting (see gtl_opt_set_i18n()): an
apostrophe between thousands in every language (60'000), a decimal comma in
French and German (2,5) and a space before the percent sign in French and
German (2,5 %). The language is read when the numbers are formatted.
gtl_label_number(...) gtl_label_percent(...)gtl_label_number(...) gtl_label_percent(...)
... |
Arguments passed on to |
A function that formats numbers
gtl_opt_set_i18n("fr_CH") gtl_label_number()(c(60000, 2.5)) gtl_label_percent(accuracy = 0.1)(0.025) gtl_opt_set_i18n("en_US") gtl_label_number()(c(60000, 2.5)) gtl_label_percent(accuracy = 0.1)(0.025)gtl_opt_set_i18n("fr_CH") gtl_label_number()(c(60000, 2.5)) gtl_label_percent(accuracy = 0.1)(0.025) gtl_opt_set_i18n("en_US") gtl_label_number()(c(60000, 2.5)) gtl_label_percent(accuracy = 0.1)(0.025)
Function to get the current language setting in full.
gtl_opt_long_language()gtl_opt_long_language()
A string with the language name (lowercase)
# With a french locale gtl_opt_set_i18n("fr_CH") gtl_opt_long_language() # With an english locale gtl_opt_set_i18n("en_US") gtl_opt_long_language()# With a french locale gtl_opt_set_i18n("fr_CH") gtl_opt_long_language() # With an english locale gtl_opt_set_i18n("en_US") gtl_opt_long_language()
This function allows setting the default language and country settings using a valid i18n code.
gtl_opt_set_i18n(code)gtl_opt_set_i18n(code)
code |
A valid i18n code (example: fr_CH) |
# Swiss french locale gtl_opt_set_i18n("fr_CH") gtl_options("language") gtl_options("country") # American english locale gtl_opt_set_i18n("en_US") gtl_options("language") gtl_options("country")# Swiss french locale gtl_opt_set_i18n("fr_CH") gtl_options("language") gtl_options("country") # American english locale gtl_opt_set_i18n("en_US") gtl_options("language") gtl_options("country")
Function that returns the short language code currently set if it is in the list of valid options. If the current language isn't in the list of valid options, the first element of the valid elements is returned.
gtl_opt_short_language(valid = c("en", "fr"))gtl_opt_short_language(valid = c("en", "fr"))
valid |
A vector with valid language options |
A string
gtl_opt_set_i18n("fr_CH") gtl_opt_short_language(valid = c("de", "fr")) # With the current local not among the valid options gtl_opt_set_i18n("en_US") gtl_opt_short_language(valid = c("de", "fr"))gtl_opt_set_i18n("fr_CH") gtl_opt_short_language(valid = c("de", "fr")) # With the current local not among the valid options gtl_opt_set_i18n("en_US") gtl_opt_short_language(valid = c("de", "fr"))
Set or get options for my package
gtl_options(...)gtl_options(...)
... |
Option names to retrieve option values or |
The following options are supported
languageThe default language
countryThe default country setting
themeThe default ggplot theme
modeThe default ggplot mode
opacityThe default opacity
# Retrieve default options gtl_options("language") gtl_options("plot_standard_width") # Change a setting and retrieve it gtl_options(plot_standard_width = 25) gtl_options("plot_standard_width")# Retrieve default options gtl_options("language") gtl_options("plot_standard_width") # Change a setting and retrieve it gtl_options(plot_standard_width = 25) gtl_options("plot_standard_width")
This function can be used to reformat the levels produced
by the santoku::lbl_dash() function.
gtl_relabel_dash(x)gtl_relabel_dash(x)
x |
A string vector of labels |
A string vector with clean labels
data <- seq(1, 20) data_cut <- santoku::chop(data, breaks = c(5, 7, 13), labels = santoku::lbl_dash(), extend = TRUE, drop = FALSE ) forcats::fct_relabel(data_cut, gtl_relabel_dash)data <- seq(1, 20) data_cut <- santoku::chop(data, breaks = c(5, 7, 13), labels = santoku::lbl_dash(), extend = TRUE, drop = FALSE ) forcats::fct_relabel(data_cut, gtl_relabel_dash)
Format numbers using scientific notation for html
gtl_sci_10_html(x)gtl_sci_10_html(x)
x |
Number to format |
A formatted expression
gtl_sci_10_html(10e6) gtl_sci_10_html(10e9)gtl_sci_10_html(10e6) gtl_sci_10_html(10e9)
This is a shortcut for Swiss canton abbreviation based on the canton name.
gtl_swiss_canton_abbr(canton_name)gtl_swiss_canton_abbr(canton_name)
canton_name |
A vector of Swiss canton names |
A vector of Swiss canton abbreviations
gtl_swiss_canton_abbr(c("Jura", "Genève", "Neuchâtel"))gtl_swiss_canton_abbr(c("Jura", "Genève", "Neuchâtel"))
This is a shortcut for Swiss canton codes based on the canton name.
gtl_swiss_canton_id(canton_name)gtl_swiss_canton_id(canton_name)
canton_name |
A vector of Swiss canton names |
A vector of Swiss canton FSO ids
gtl_swiss_canton_id(c("Jura", "Genève", "Neuchâtel"))gtl_swiss_canton_id(c("Jura", "Genève", "Neuchâtel"))
Translate function
gtl_translate_enfr(english, french, german = english)gtl_translate_enfr(english, french, german = english)
english |
English string |
french |
French string |
german |
German string, English when not given A function that returns the english, french or german argument depending on the current language setting. Any other language gets the english one. |
String depending on package language option
gtl_opt_set_i18n("fr_CH") # Set language to french gtl_translate_enfr("Hello world!", "Bonjour le monde !") gtl_opt_set_i18n("de_CH") # Set language to german gtl_translate_enfr("Hello world!", "Bonjour le monde !", "Hallo Welt!") gtl_opt_set_i18n("en_US") # Set language to english gtl_translate_enfr("Hello world!", "Bonjour le monde !")gtl_opt_set_i18n("fr_CH") # Set language to french gtl_translate_enfr("Hello world!", "Bonjour le monde !") gtl_opt_set_i18n("de_CH") # Set language to german gtl_translate_enfr("Hello world!", "Bonjour le monde !", "Hallo Welt!") gtl_opt_set_i18n("en_US") # Set language to english gtl_translate_enfr("Hello world!", "Bonjour le monde !")
Creates translation function for named string list
gtl_translator(dictionary)gtl_translator(dictionary)
dictionary |
A list of translations |
A function that translates
translations <- list( "maison" = "house", "chapeau" = "hat", "chat" = "cat" ) translate_to_english <- gtl_translator(translations) translate_to_english("maison") translate_to_english("chat")translations <- list( "maison" = "house", "chapeau" = "hat", "chat" = "cat" ) translate_to_english <- gtl_translator(translations) translate_to_english("maison") translate_to_english("chat")