Title: | Support for Geography Packages |
---|---|
Description: | Support functions for the GeoVerse packages. |
Authors: | Pascal Burkhard [aut, cre] |
Maintainer: | Pascal Burkhard <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0.9000 |
Built: | 2024-11-26 08:27:16 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")
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
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()
Determine the Köppen climate based on temperature, precipitation and the latitude.
gtl_koppen_code(temp, prec, lat)
gtl_koppen_code(temp, prec, lat)
temp |
A vector with temperatures in degree Celsius for each month |
prec |
A vector with precipitations in millimeters for each month |
lat |
The latitude in degrees |
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), lat = 6 )
# 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), lat = 6 )
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
language
The default language
country
The default country setting
theme
The default ggplot theme
mode
The default ggplot mode
opacity
The 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)
gtl_translate_enfr(english, french)
english |
English string |
french |
French string A function that returns the english or french argument depending on the current language setting. |
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("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("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")