Skip to content

Commit

Permalink
Replace function with data object
Browse files Browse the repository at this point in the history
Fix #134
  • Loading branch information
damianooldoni committed Jul 17, 2024
1 parent 401cd19 commit b469f1d
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 40 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^appveyor\.yml$
^\.github$
^codecov\.yml$
^data-raw$
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export(get_table_pathways)
export(indicator_introduction_year)
export(indicator_native_range_year)
export(indicator_total_year)
export(pathways_cbd)
export(update_download_list)
export(verify_taxa)
export(visualize_pathways_level1)
Expand Down
10 changes: 10 additions & 0 deletions R/data-pathways_cbd.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' Pathways of introduction as defined by the Convention on Biological Diversity
#'
#' This data frame contains all pathways of introdution at level 1
#' (`pathway_level1`) and level 2 (`pathway_level2`) as defined by the
#' Convention on Biological Diversity (CBD). Added pathway `unknown` at level 1
#' and level 2 for classifying taxa without pathway (at level 1 or level 2)
#' information.
#'
#' @family pathways data
"pathways_cbd"
2 changes: 1 addition & 1 deletion R/visualize_pathways_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ visualize_pathways_level1 <- function(df,
))
# Import all CBD pathways level 1
pathways_level1_all <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::distinct(.data$pathway_level1)
# Select pathways
if (!is.null(pathways)) {
Expand Down
6 changes: 3 additions & 3 deletions R/visualize_pathways_level2.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param df df.
#' @param chosen_pathway_level1 character. A pathway level 1. If CBD standard is
#' followed (see argument `cbd_standard`), one of the level 1 pathways from
#' `pathways_cbd()`.
#' `pathways_cbd`.
#' @param category `NULL` (default) or character. One of the kingdoms as given
#' in GBIF or `Chordata` (the phylum) or `Not Chordata` (all other phyla of
#' `Animalia`):
Expand Down Expand Up @@ -51,7 +51,7 @@
#' @param first_observed character. Name of the column of `df` containing
#' information about year of introduction. Default: `"first_observed"`.
#' @param cbd_standard logical. If `TRUE` the values of pathway level 2 are
#' checked based on CBD standard as returned by `pathways_cbd()`. Error is
#' checked based on CBD standard in `pathways_cbd`. Error is
#' returned if unmatched values are found. If `FALSE`, a warning is returned.
#' Default: `TRUE`.
#' @param title `NULL` or character. Title of the graph. Default: `NULL`.
Expand Down Expand Up @@ -398,7 +398,7 @@ visualize_pathways_level2 <- function(df,
))
# Import all CBD pathways level 2 within chosen pathway level 1
pathways_level2_all <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::filter(.data$pathway_level1 == chosen_pathway_level1) %>%
dplyr::distinct(.data$pathway_level2)
# Select pathways
Expand Down
4 changes: 2 additions & 2 deletions R/visualize_pathways_year_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' @param first_observed character. Name of the column of `df` containing
#' information about year of introduction. Default: `"first_observed"`.
#' @param cbd_standard logical. If `TRUE` the values of pathway level 1 are
#' checked based on CBD standard as returned by `pathways_cbd()`. Error is
#' checked based on CBD standard in `pathways_cbd`. Error is
#' returned if unmatched values are found. If `FALSE`, a warning is returned.
#' Default: `TRUE.`
#' @param title `NULL` or character. Title of the graph. Default: `NULL`.
Expand Down Expand Up @@ -342,7 +342,7 @@ visualize_pathways_year_level1 <- function(
))
# Import all CBD pathways level 1
pathways_level1_all <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::distinct(.data$pathway_level1)
# Select pathways
if (!is.null(pathways)) {
Expand Down
4 changes: 2 additions & 2 deletions R/visualize_pathways_year_level2.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' @param first_observed character. Name of the column of `df` containing
#' information about year of introduction. Default: `"first_observed"`.
#' @param cbd_standard logical. If `TRUE` the values of pathway level 1 are
#' checked based on CBD standard as returned by `pathways_cbd()`. Error is
#' checked based on CBD standard in `pathways_cbd()`. Error is
#' returned if unmatched values are found. If `FALSE`, a warning is returned.
#' Default: `TRUE`.
#' @param title `NULL` or character. Title of the graph. Default: `NULL`.
Expand Down Expand Up @@ -405,7 +405,7 @@ visualize_pathways_year_level2 <- function(
))
# Import all CBD pathways level 2 within chosen pathway level 1
pathways_level2_all <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::filter(.data$pathway_level1 == chosen_pathway_level1) %>%
dplyr::distinct(.data$pathway_level2)
# Select pathways
Expand Down
17 changes: 4 additions & 13 deletions R/pathways_cbd.R → data-raw/pathways_cbd.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
#' 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
#' 2 for classifying taxa without pathway (at level 1 or level 2) information.
#'
#' @return A tibble data.frame with 2 columns: `pathway_level1` and
#' `pathway_level2`.
#' @export
#' @usage pathways_cbd()
# Code to prepare `pathwayscbd` dataset

pathways_cbd <- function() pathwayscbd

pathwayscbd <- dplyr::tibble(
pathways_cbd <- dplyr::tibble(
pathway_level1 = c(
rep("release", 9),
rep("escape", 13),
Expand Down Expand Up @@ -75,3 +64,5 @@ pathwayscbd <- dplyr::tibble(
"unknown"
)
)

# Then run `usethis::use_data(pathways_cbd, overwrite = TRUE)`
Binary file added data/pathways_cbd.rda
Binary file not shown.
24 changes: 14 additions & 10 deletions man/pathways_cbd.Rd

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

4 changes: 2 additions & 2 deletions man/visualize_pathways_level2.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/visualize_pathways_year_level1.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/visualize_pathways_year_level2.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-visualize_pathways_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ input_test_df <- read.delim(
)

valid_pathways <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::distinct(pathway_level1) %>%
dplyr::pull()

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-visualize_pathways_level2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ input_test_df <- read.delim(


valid_pathways_escape <-
pathways_cbd() %>%
pathways_cbd %>%
filter(pathway_level1 == "escape") %>%
distinct(pathway_level2) %>%
pull()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-visualize_pathways_year_level1.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ n_first_observed_na <-
nrow(input_test_df_with_nas) - nrow(input_test_df)

valid_pathways <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::distinct(pathway_level1) %>%
dplyr::pull()

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-visualize_pathways_year_level2.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ input_test_df_other_colnames <-
)

valid_pathways_escape <-
pathways_cbd() %>%
pathways_cbd %>%
dplyr::filter(pathway_level1 == "escape") %>%
dplyr::distinct(pathway_level2) %>%
dplyr::pull()
Expand Down

0 comments on commit b469f1d

Please sign in to comment.