Skip to content

Commit

Permalink
Merge branch 'main' into style-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
damianooldoni committed Jul 17, 2024
2 parents eb35c7b + 5e293f2 commit 9f6ad6b
Show file tree
Hide file tree
Showing 25 changed files with 143 additions and 127 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ Encoding: UTF-8
LazyData: true
LazyDataCompression: bzip2
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
7 changes: 2 additions & 5 deletions R/apply_decision_rules.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@
#' - (`dr_1` is `TRUE` and `dr_3` is `FALSE`) or (`dr_1`, `dr_2` and `dr_3` are
#' `FALSE`): `em = 1` (unclear)
#' @examples
#' \dontrun{
#' df <- dplyr::tibble(
#' taxonID = c(rep(1008955, 10), rep(2493598, 3)),
#' y = c(seq(2009, 2018), seq(2016, 2018)),
#' obs = c(1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 3, 0)
#' )
#' apply_decision_rules(df,
#' eval_year = c(2016, 2017, 2018),
#' eval_year = 2016,
#' y_var = "obs",
#' taxonKey = "taxonID",
#' year = y
#' year = "y"
#' )
#' }
#'
apply_decision_rules <- function(df,
y_var = "ncells",
eval_year,
Expand Down
4 changes: 2 additions & 2 deletions R/apply_gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' @param x_label character. x-axis label of output plot. Default: `"year"`.
#' @param y_label character. y-axis label of output plot. Default: `"number of
#' observations"`.
#' @param saveplot logical. If `TRUE` the plots are authomatically saved.
#' @param saveplot logical. If `TRUE` the plots are automatically saved.
#' Default: `FALSE`.
#' @param dir_name character. Path of directory where saving plots. If path
#' doesn't exists, directory will be created. Example: "./output/graphs/". If
Expand Down Expand Up @@ -92,7 +92,7 @@
#'
#' \item `first_derivative`: df. Data.frame with details of first derivatives.
#' It contains the following columns:
#' - `smooth`: smoooth identifier. Example: `s(year)`.
#' - `smooth`: smooth identifier. Example: `s(year)`.
#' - `derivative`: numeric. Value of first derivative.
#' - `se`: numeric. Standard error of `derivative`.
#' - `crit`: numeric. Critical value required such that
Expand Down
2 changes: 1 addition & 1 deletion R/climate_match.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' zones in the target nation or region
#' - `spatial` a sf object containing the observations used
#' in the analysis
#' - `current_map` a leaflet object displaying the degree of wordlwide
#' - `current_map` a leaflet object displaying the degree of worldwide
#' climate match with the climate from 1980 till 2016
#' - `future_maps` a list of leaflet objects for each future climate
#' scenario, displaying the degree of climate match
Expand Down
6 changes: 3 additions & 3 deletions R/data-legends.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#'
#' Each data.frame contains two columns:
#' - `GRIDCODE`: (numeric) grid value corresponding to a climate zone
#' - `Classification`: (character) Koppen-{G}eiger climate classification value
#' - `Description`: (character) verbose description of the Koppen-{G}eiger
#' - `Classification`: (character) Koppen-Geiger climate classification value
#' - `Description`: (character) verbose description of the Koppen-Geiger
#' climate zone, e.g. "Tropical rainforest climate"
#' - `Group`: (character) group the Koppen-{G}eiger climate zone belongs to,
#' - `Group`: (character) group the Koppen-Geiger climate zone belongs to,
#' e.g. "Tropical"
#' - `Precipitation Type`: (character) Type of precipitations associated to
#' the climate zone, e.g. "Rainforest"
Expand Down
2 changes: 1 addition & 1 deletion R/gbif_has_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param taxon_key (single numeric or character) a single taxon key.
#' @param ... one or more GBIF distribution properties and related values.
#' Up to now it supports the following properties:
#' country (and its synoynym: countryCode), status (and its synonym:
#' country (and its synonym: countryCode), status (and its synonym:
#' occurrenceStatus) and establishmentMeans.
#' @return a logical, TRUE or FALSE.
#' @export
Expand Down
42 changes: 20 additions & 22 deletions R/gbif_verify_keys.R
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
#' Check keys against GBIF Backbone Taxonomy
#'
#' This function performs three checks:
#' \itemize{
#' \item{\code{keys} are valid GBIF taxon keys. That means that adding a key
#' - `keys` are valid GBIF taxon keys. That means that adding a key
#' at the end of the URL https://www.gbif.org/species/ returns a GBIF page
#' related to a taxa.}
#' \item{\code{keys} are taxon keys of the GBIF Backbone Taxonomy checklist.
#' related to a taxa.
#' - `keys` are taxon keys of the GBIF Backbone Taxonomy checklist.
#' That means that adding a key at the end of the URL
#' https://www.gbif.org/species/ returns a GBIF page related to a taxa of the
#' GBIF Backbone.)}
#' \item{\code{keys} are synonyms of other taxa (taxonomicStauts neither
#' \code{ACCEPTED} nor \code{DOUBTFUL}).}
#' }.
#' GBIF Backbone.)
#' - `keys` are synonyms of other taxa (taxonomicStatus neither
#' `ACCEPTED` nor `DOUBTFUL`).
#' @param keys (character or numeric) a vector, a list, or a data.frame
#' containing the keys to verify.
#' @param col_keys (character) name of column containing keys in case
#' \code{keys} is a data.frame.
#' `keys` is a data.frame.
#'
#' @return a data.frame with the following columns:
#' \itemize{
#' \item{\code{key}}{:(numeric) keys as input keys.}
#' \item{\code{is_taxonKey}} {: (logical) is the key a valid GBIF taxon
#' key?}
#' \item{\code{is_from_gbif_backbone}} {:(logical) is the key a valid taxon
#' key from GBIF Backbone Taxonomy checklist?}
#' \item{\code{is_synonym}} {: (logical) is the key related to a synonym (not
#' \code{ACCEPTED} or \code{DOUBTFUL})?}
#' }
#' If a key didn't pass the first check (\code{is_taxonKey = FALSE}) then
#' \code{NA} for other two columns. If a key didn't pass the second check
#' (\code{is_from_gbif_backbone = FALSE}) then \code{is_synonym} = \code{NA}.
#' - `key`: (numeric) keys as input keys.
#' - `is_taxonKey`: (logical) is the key a valid GBIF taxon key?
#' - `is_from_gbif_backbone`: (logical) is the key a valid taxon key from
#' GBIF Backbone Taxonomy checklist?
#' - `is_synonym`: (logical) is the key related to a synonym (not
#' `ACCEPTED` or `DOUBTFUL`)?
#'
#' If a key didn't pass the first check (`is_taxonKey` = `FALSE`) then
#' `NA` for other two columns. If a key didn't pass the second check
#' (`is_from_gbif_backbone` = `FALSE`) then `is_synonym` = `NA`.
#'
#' @export
#' @importFrom dplyr .data %>%
#' @importFrom rlang !!
#' @examples
#' \dontrun{
#' # input is a vector
#' keys1 <- c(
#' "12323785387253", # invalid GBIF taxonKey
Expand All @@ -50,7 +48,6 @@
#' )
#' # input is a named list
#' keys3 <- keys1
#' library(purrr)
#' names(keys3) <- purrr::map_chr(
#' c(1:length(keys3)),
#' ~ paste(sample(c(0:9, letters, LETTERS), 3),
Expand All @@ -64,6 +61,7 @@
#' gbif_verify_keys(keys2, col_keys = "keys")
#' gbif_verify_keys(keys3)
#' gbif_verify_keys(keys4)
#' }
gbif_verify_keys <- function(keys, col_keys = "key") {
assertthat::assert_that(is.data.frame(keys) | is.vector(keys),
msg = "keys should be a vector, a named list or a data.frame."
Expand Down
28 changes: 16 additions & 12 deletions R/indicator_native_range_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' [countYearProvince](https://github.com/inbo/reporting-rshiny-grofwildjacht/blob/exoten/reporting-grofwild/R/countYearProvince.R)
#' plot from reporting - rshiny - grofwildjacht
#' @param df input data.frame.
#' @param years (numeric) vector years we are interested to. If \code{NULL}
#' @param years (numeric) vector years we are interested to. If `NULL`
#' (default) all years from minimum and maximum of years of first observation
#' are taken into account.
#' @param type character, native_range level of interest should be one of
Expand All @@ -16,22 +16,26 @@
#' species".
#' @param relative (logical) if TRUE (default), each bar is standardised before
#' stacking.
#' @param taxon_key_col character. Name of the column of \code{df} containing
#' taxon IDs. Default: \code{"key"}.
#' @param taxon_key_col character. Name of the column of `df` containing
#' taxon IDs. Default: `"key"`.
#' @param first_observed (character) Name of the column in `data`
#' containing temporal information about introduction of the alien species.
#' Expressed as years.
#' @return list with: \itemize{ \item{'static_plot': }{ggplot object, for a
#' @return list with:
#' - `static_plot`: ggplot object, for a
#' given species the observed number per year and per native range is plotted
#' in a stacked bar chart} \item{'interactive_plot': }{plotly object, for a
#' in a stacked bar chart.
#' - `interactive_plot`: plotly object, for a
#' given species the observed number per year and per native range is plotted
#' in a stacked bar chart} \item{'data': }{data displayed in the plot, as
#' data.frame with: \itemize{ \item{'year': }{year at which the species were
#' introduced} \item{'native_range': }{native range of the introduced species}
#' \item{'n': }{number of species introduced from the native range for a given
#' year} \item{'total': }{total number of species, from all around the world,
#' introduced during a given year} \item{'perc': }{percentage of species
#' introduced from the native range for a given year. (n/total)*100} } } }
#' in a stacked bar chart.
#' - `data`: data displayed in the plot, as a data.frame with:
#' - `year`: year at which the species were introduced.
#' - `native_range`: native range of the introduced species.
#' - `n`: number of species introduced from the native range for a given year.
#' - `total`: total number of species, from all around the world, introduced.
#' during a given year.
#' - `perc`: percentage of species introduced from the native range for a
#' given year, `n`/`total`*100.
#' @export
#' @importFrom dplyr %>% .data
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/pathways_cbd.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Pathways of introdcution as defined by CBD
#' Pathways of introduction as defined by CBD
#'
#' Function to get all CBD pathays of introdution at level 1 (`pathway_level1`)
#' and level 2 (`pathway_level2`). Added pathway `unknown` at level 1 and level
Expand Down
2 changes: 1 addition & 1 deletion R/update_download_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function opens a (tab-separated) text file containing all occurrence
#' downloads from GBIF and updates the status of all downloads with status
#' `RUNNING` or `PREPARING`. If the specifid download is not present it will be add.
#' `RUNNING` or `PREPARING`. If the specified download is not present it will be add.
#'
#' If a download key is passed which is not present in the file it will be added
#' as a new line.
Expand Down
8 changes: 4 additions & 4 deletions R/visualize_pathways_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ visualize_pathways_level1 <- function(df,
if (!is.null(y_lab)) {
assertthat::assert_that(length(y_lab) == 1)
}
# rename to default column name
# Rename to default column name
df <-
df %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(kingdom_names)), ~"group") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(taxon_names)), ~"taxonKey") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(first_observed)), ~"first_observed") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level1_names)), ~"pathway_level1")
# handle asymmetric category system (Chordata, Not Chordta are not kingdoms)
# Handle asymmetric category system (Chordata, Not Chordta are not kingdoms)
if (!is.null(category)) {
if (!category %in% c("Chordata", "Not Chordata")) {
df <- df %>% dplyr::filter(.data$group == category)
Expand All @@ -293,7 +293,7 @@ visualize_pathways_level1 <- function(df,

if (!is.null(facet_column)) {
if (facet_column == "kingdom") {
# category NULL by assertion
# Category NULL by assertion
df$kingdom <- df$group
}
}
Expand Down Expand Up @@ -363,7 +363,7 @@ visualize_pathways_level1 <- function(df,
} else {
warning(message_invalid_pathways)
}
# dplyr::distinct taxa
# Distinct taxa
if (!is.null(facet_column)) {
df <-
df %>%
Expand Down
23 changes: 14 additions & 9 deletions R/visualize_pathways_level2.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,24 @@ visualize_pathways_level2 <- function(df,
)
assertthat::assert_that(length(y_lab) == 1)
}
# rename to default column name
# Rename to default column name
df <-
df %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(kingdom_names)), ~"group") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(taxon_names)), ~"taxonKey") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(first_observed)), ~"first_observed") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level1_names)), ~"pathway_level1") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level2_names)), ~"pathway_level2")
dplyr::rename_at(dplyr::vars(tidyselect::all_of(kingdom_names)),
~"group") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(taxon_names)),
~"taxonKey") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(first_observed)),
~"first_observed") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level1_names)),
~"pathway_level1") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level2_names)),
~"pathway_level2")
# Select data with the chosen pathway level 1
df <-
df %>%
dplyr::filter(.data$pathway_level1 == chosen_pathway_level1)
# handle asymmetric category system (Chordata, Not Chordta are not kingdoms)
# Handle asymmetric category system (Chordata, Not Chordta are not kingdoms)
if (!is.null(category)) {
if (!category %in% c("Chordata", "Not Chordata")) {
df <- df %>% dplyr::filter(.data$group == category)
Expand Down Expand Up @@ -435,7 +440,7 @@ visualize_pathways_level2 <- function(df,
} else {
warning(message_invalid_pathways)
}
# dplyr::distinct taxa
# Distinct taxa
if (!is.null(facet_column)) {
df <-
df %>%
Expand All @@ -448,7 +453,7 @@ visualize_pathways_level2 <- function(df,
pathway_level2 = factor(.data$pathway_level2, levels = pathways)
) %>%
dplyr::as_tibble()
# dplyr::distinct taxa without facet
# Distinct taxa without facet
data_top_graph <-
df %>%
dplyr::distinct(
Expand Down
21 changes: 11 additions & 10 deletions R/visualize_pathways_year_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,16 @@ visualize_pathways_year_level1 <- function(
)
assertthat::assert_that(length(y_lab) == 1)
}
# rename to default column name
# Rename to default column name
df <-
df %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(kingdom_names)), ~"group") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(taxon_names)), ~"taxonKey") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(first_observed)), ~"first_observed") %>%
dplyr::rename_at(dplyr::vars(tidyselect::all_of(pathway_level1_names)), ~"pathway_level1")

# handle asymmetric category system (Chordata, Not Chordata are not kingdoms)
dplyr::rename_at(dplyr::vars(dplyr::all_of(kingdom_names)), ~"group") %>%
dplyr::rename_at(dplyr::vars(dplyr::all_of(taxon_names)), ~"taxonKey") %>%
dplyr::rename_at(dplyr::vars(dplyr::all_of(first_observed)),
~"first_observed") %>%
dplyr::rename_at(dplyr::vars(dplyr::all_of(pathway_level1_names)),
~"pathway_level1")
# Handle asymmetric category system (Chordata, Not Chordata are not kingdoms)
if (!is.null(category)) {
if (!category %in% c("Chordata", "Not Chordata")) {
df <- df %>% dplyr::filter(.data$group == category)
Expand Down Expand Up @@ -399,7 +400,7 @@ visualize_pathways_year_level1 <- function(
df %>%
dplyr::filter(!is.na(first_observed))
}
# dplyr::distinct taxa
# Distinct taxa
if (is.null(facet_column)) {
df <-
df %>%
Expand Down Expand Up @@ -460,7 +461,7 @@ visualize_pathways_year_level1 <- function(
df %>%
dplyr::mutate(pathway_level1 = factor(.data$pathway_level1, levels = pathways))

# dplyr::count number of taxa per pathway_level1 over time
# Count number of taxa per pathway_level1 over time
data_top_graph <-
df %>%
dplyr::group_by(
Expand Down Expand Up @@ -499,7 +500,7 @@ visualize_pathways_year_level1 <- function(
data_top_graph = data_top_graph,
data_facet_graph = NULL))
} else {
# dplyr::count number of taxa per pathway_level1 per facet over time
# Count number of taxa per pathway_level1 per facet over time
data_facet_graph <-
df %>%
dplyr::group_by(
Expand Down
Loading

0 comments on commit 9f6ad6b

Please sign in to comment.