Skip to content

Commit

Permalink
GIFT_traits_tax() improved: better message, argument agreement added
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredenelle committed Aug 21, 2023
1 parent 1833073 commit 156e401
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 0 additions & 1 deletion R/GIFT_traits.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ GIFT_traits <- function(
values for biases. bias_ref and bias_deriv arguments are ignored.")
}


# 2. Function ----
# Get species names
message("\nRetrieving species' names.\n")
Expand Down
25 changes: 22 additions & 3 deletions R/GIFT_traits_tax.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#' @param trait_IDs a character string indicating which trait you want to
#' retrieve. Traits must belong to the available list of traits.
#'
#' @param agreement Percentage of resources that agree on an aggregated trait
#' value, entries below this threshold will be omitted.
#'
#' @param bias_ref When `FALSE`, exclude entries that are only based on a
#' resource that potentially introduces a bias (e.g. a resource only including
#' trees).
Expand Down Expand Up @@ -51,15 +54,26 @@
#' @importFrom utils setTxtProgressBar txtProgressBar
#'
#' @export

GIFT_traits_tax <- function(
trait_IDs = "", bias_ref = TRUE, bias_deriv = TRUE,
trait_IDs = "", agreement = 0.66, bias_ref = TRUE, bias_deriv = TRUE,
api = "https://gift.uni-goettingen.de/api/extended/",
GIFT_version = "latest"){

# 1. Controls ----
# Arguments
check_trait_IDs(trait_IDs)

if(!is.numeric(agreement)){
stop("agreement must be a numeric between 0 and 1 indicating the proportion
of original trait values that needs to support the aggregated value in
case of categorical traits.")
} else if(agreement > 1 | agreement < 0){
stop("agreement must be a numeric between 0 and 1 indicating the proportion
of original trait values that needs to support the aggregated value in
case of categorical traits.")
}

check_bias_ref(bias_ref)
check_bias_deriv(bias_deriv)
check_api(api)
Expand Down Expand Up @@ -163,13 +177,18 @@ GIFT_traits_tax <- function(
length(trait_IDs)){
message(paste0(
"The following traits were not available at the taxonomic level: ",
trait_IDs[!(trait_IDs %in% unique(trait_list$trait_ID))]))
paste0(trait_IDs[!(trait_IDs %in% unique(trait_list$trait_ID))],
sep = " ", collapse = "")))
}

# Make certain columns numeric
trait_list <- dplyr::mutate_at(
trait_list, c("taxon_ID", "agreement", "negative"), as.numeric)

# Removing values below the agreement threshold
trait_list <- trait_list[which(trait_list$agreement >= agreement |
is.na(trait_list$agreement)), ]

# Add species names
# trait_list <- dplyr::left_join(trait_list,
# species[, c("work_ID", "work_species",
Expand Down
4 changes: 4 additions & 0 deletions man/GIFT_traits_tax.Rd

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

0 comments on commit 156e401

Please sign in to comment.