diff --git a/R/as_wide_table.R b/R/as_wide_table.R index 88657be..eec13b9 100644 --- a/R/as_wide_table.R +++ b/R/as_wide_table.R @@ -1,6 +1,6 @@ -#' Create a single wide table from the AusTraits data object +#' Create a single wide table from a traits.build data object #' -#' @param austraits austraits data object +#' @param database traits.build database (list object) #' #' @return A single wide table with collapsed contexts and locations text and with #' some cols renamed for alignment with other resources @@ -8,19 +8,18 @@ #' #' @examples #' \dontrun{ -#' data <- austraits -#' data %>% as_wide_table() +#' austraits %>% as_wide_table() #' } #' @importFrom stats family #' @importFrom utils methods -as_wide_table <- function(austraits){ +as_wide_table <- function(database){ # Check compatability - status <- check_compatibility(austraits) + status <- check_compatibility(database) # If compatible if(!status){ - function_not_supported(austraits) + function_not_supported(database) } # Function to collapse columns in locations and contexts into single column @@ -33,39 +32,39 @@ as_wide_table <- function(austraits){ } ################################################################################ - # Define and adapt each table in the list of austraits to prepare for the wide table format + # Define and adapt each table in the list of a traits.build database to prepare for the wide table format # The contexts table needs the contexts collapsed to one context name per site - austraits %>% - join_contexts_old(collapse_context = TRUE) -> austraits + database %>% + join_contexts_old(collapse_context = TRUE) -> database # Getting rid of the columns that will soon be deleted in the next austraits release and renaming the description column - austraits$methods <- - austraits$methods %>% + database$methods <- + database$methods %>% dplyr::rename(dataset_description = "description") %>% dplyr::distinct() # collapse into one column - austraits$locations <- - austraits$locations %>% + database$locations <- + database$locations %>% dplyr::filter(value!="unknown") %>% dplyr::rename("property" = "location_property") %>% split(., .$dataset_id) %>% purrr::map_dfr(process_table3) # rename taxonomic_dataset field to reflect the APC/APNI name matching process better - austraits$taxa <- - austraits$taxa %>% + database$taxa <- + database$taxa %>% dplyr::distinct() - austraits_wide <- - austraits$traits %>% - dplyr::left_join(by=c("dataset_id", "location_id"), austraits$locations) %>% - dplyr::left_join(by=c("dataset_id", "method_id", "trait_name"), austraits$methods) %>% - dplyr::left_join(by=c("taxon_name"), austraits$taxa) + database_wide <- + database$traits %>% + dplyr::left_join(by=c("dataset_id", "location_id"), database$locations) %>% + dplyr::left_join(by=c("dataset_id", "method_id", "trait_name"), database$methods) %>% + dplyr::left_join(by=c("taxon_name"), database$taxa) # reorder the names to be more intuitive - austraits_wide %>% dplyr::select( + database_wide %>% dplyr::select( # The most useful (if you are filtering for just one taxon_name) "dataset_id", "observation_id", "trait_name", "taxon_name", "value", "unit", @@ -92,7 +91,7 @@ as_wide_table <- function(austraits){ "taxon_rank", "genus", "family" ) - austraits_wide + database_wide } #' Collapse columns into text string diff --git a/R/bind_databases.R b/R/bind_databases.R index ac65c0f..a90eec7 100644 --- a/R/bind_databases.R +++ b/R/bind_databases.R @@ -4,7 +4,7 @@ #' database object as a large list. #' #' @param ... Arguments passed to other functions -#' @param databases List of traits.build databases to bind together (lists of tibbles) +#' @param databases List of traits.build databases to bind together #' #' @return Compiled database as a single large list #' @importFrom rlang .data diff --git a/R/bind_trait_values.R b/R/bind_trait_values.R index 717e1a3..7b17005 100644 --- a/R/bind_trait_values.R +++ b/R/bind_trait_values.R @@ -3,7 +3,7 @@ #' @description This function condenses data for studies that have multiple observations for a given trait into a single row. #' This function concatenates multiple values into a single cell #' @usage bind_trait_values(trait_data) -#' @param trait_data The trait data frame generated from austraits - see example +#' @param trait_data the traits table in a traits.build database -- see example #' @return tibble that is condensed down where multiple observations in value, value_type and replicates are collapsed down and separated by '--' #' #' @examples diff --git a/R/check_compatibility.R b/R/check_compatibility.R index 8691fc2..d8e6d3a 100644 --- a/R/check_compatibility.R +++ b/R/check_compatibility.R @@ -1,19 +1,19 @@ #' @title Check compatibility of traits.build object #' @description Function to check whether the data object has been compiled by the traits.build workflow and #' therefore has a data structure that is appropriate for use with austraits functions. -#' @param austraits dataframe generated by traits build +#' @param database traits.build database (list object) #' #' @return logical (T/F) output and messaging for uncompatible versions #' #' @examples #' \dontrun{ -#' check_compatibility(austraits) +#' check_compatibility(database) #' } #' @author Elizabeth Wenk - e.wenk@unsw.edu.au -check_compatibility <- function(austraits) { +check_compatibility <- function(database) { - if (is.null(austraits$metadata)) { + if (is.null(database$metadata)) { compatible <- FALSE @@ -22,9 +22,9 @@ check_compatibility <- function(austraits) { } else { compiled_by_traits.build <- - austraits$metadata$related_identifiers %>% + database$metadata$related_identifiers %>% convert_list_to_df2() %>% - dplyr::filter(relation_type == "isCompiledBy") |> + dplyr::filter(relation_type == "isCompiledBy") %>% dplyr::filter(stringr::str_detect(identifier, "github.com/traitecoevo/traits.build")) if(is.null(compiled_by_traits.build) | nrow(compiled_by_traits.build) > 0) { @@ -46,13 +46,13 @@ check_compatibility <- function(austraits) { #' Check compatibility of traits table #' -#' @param traits table in traits.build object +#' @param trait_data the traits table in a traits.build database #' #' @return logical, TRUE indicating version traits table came from traits.build version > 1.0 -check_traits_compatibility <- function(traits){ +check_traits_compatibility <- function(trait_data){ # Check compatibility using column - if(any(names(traits) %in% c("treatment_context_id", "repeat_measurements_id"))){ + if(any(names(trait_data) %in% c("treatment_context_id", "repeat_measurements_id"))){ compatible <- TRUE } else compatible <- FALSE diff --git a/R/extract_data.R b/R/extract_data.R index 28acc8f..5d42cdf 100644 --- a/R/extract_data.R +++ b/R/extract_data.R @@ -6,7 +6,7 @@ #' The output a traits.build formatted database with all tables subset #' based on the specified table, column (variable) and column value. #' -#' @param database traits.build database +#' @param database traits.build database (list object) #' @param table Table within a traits.build database #' @param col Column name within the specified table. #' @param col_value Value (of column, from with a table) that is used to subset database. This can be a single value or a vector. It includes partial string matches. diff --git a/R/extract_dataset.R b/R/extract_dataset.R index dc92865..06df0be 100644 --- a/R/extract_dataset.R +++ b/R/extract_dataset.R @@ -3,7 +3,7 @@ #' @description Function to subset all data associated with a particular dataset from a traits.build relational database. #' #' @usage extract_dataset(database, dataset_id) -#' @param database a large list of tibbles built by `traits.build` workflow +#' @param database traits.build database (list object) #' @param dataset_id character string that matches a `dataset_id` in the database #' @return List of tibbles containing all traits.build data and metadata for the specified dataset(s). #' @details diff --git a/R/extract_taxa.R b/R/extract_taxa.R index d95343a..0db5ca5 100644 --- a/R/extract_taxa.R +++ b/R/extract_taxa.R @@ -2,7 +2,7 @@ #' #' @description Function to subset of all data associated with a particular taxon from a traits.build relational database. #' -#' @param database a large list of tibbles built by `traits.build` workflow +#' @param database traits.build database (list object) #' @param family character string of family or families #' @param genus character string of genus or genera #' @param taxon_name character string of taxon name(s) @@ -19,8 +19,8 @@ #' #' @examples #' \dontrun{ -#'extract_taxa(austraits, family = "Proteaceae") -#'extract_taxa(austraits, genus = "Acacia") +#'extract_taxa(database = austraits, family = "Proteaceae") +#'extract_taxa(database = austraits, genus = "Acacia") #' } #' @author Fonti Kar - f.kar@unsw.edu.au #' @export diff --git a/R/extract_trait.R b/R/extract_trait.R index c5a1af1..d4f5941 100644 --- a/R/extract_trait.R +++ b/R/extract_trait.R @@ -3,7 +3,7 @@ #' @description Function to subset all data associated with a particular trait from a traits.build relational database. #' #' @usage extract_trait(database, trait_names, taxon_names) -#' @param database a large list of tibbles built by `traits.build` +#' @param database traits.build database (list object) #' @param trait_names character string of trait(s) for which data will be extracted #' @param taxon_names optional argument, specifying taxa for which data will be extracted #' @return List of tibbles containing all traits.build data and metadata for the specified trait(s). @@ -19,7 +19,7 @@ #' #' @examples #' \dontrun{ -#'extract_trait(database, "wood_density", taxon_name = "Acacia celsa") +#'extract_trait(database = austraits, trait_names = "wood_density", taxon_names = "Acacia celsa") #' } #' @author Daniel Falster - daniel.falster@unsw.edu.au #' @export diff --git a/R/flatten_database.R b/R/flatten_database.R index 83d06ac..9789a7d 100644 --- a/R/flatten_database.R +++ b/R/flatten_database.R @@ -6,7 +6,7 @@ #' but all measurement-related metadata (methods, location properties, context properties, contributors) #' are now included as additional columns in a single table. #' -#' @param database A traits.build database +#' @param database traits.build database (list object) #' @param format A parameter for the locations, contexts and data contributors tables specifying how data are packed. #' All three can be formatted as a single compacted column(s) will have a human readable column ("single_column_pretty") #' or using json ("single_column_json") syntax. For location properties or context properties there is also diff --git a/R/join_all.R b/R/join_.R similarity index 85% rename from R/join_all.R rename to R/join_.R index e78df05..729a628 100644 --- a/R/join_all.R +++ b/R/join_.R @@ -2,7 +2,7 @@ #' @description Function to merge geographic coordinates (latitude/longitude) #' stored in the locations table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @return traits.build list object, but with additional fields (columns) #' for latitude and longitude appended to `traits` dataframe #' @details @@ -17,34 +17,34 @@ #' #' @examples #' \dontrun{ -#' (austraits %>% join_location_coordinates)$traits +#' (database %>% join_location_coordinates)$traits #' } #' #' @export -join_location_coordinates <- function(austraits) { +join_location_coordinates <- function(database) { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } location_coordinates <- - austraits$locations %>% + database$locations %>% dplyr::filter(location_property %in% c("latitude (deg)", "longitude (deg)")) %>% tidyr::pivot_wider(names_from = location_property, values_from = value) # variables to join_ by depends on if location_name already in traits table # from joining coordinates for instances - join_vars <- intersect(names(austraits$traits), c("dataset_id", "location_id", "location_name")) + join_vars <- intersect(names(database$traits), c("dataset_id", "location_id", "location_name")) if (any(stringr::str_detect(names(location_coordinates), "latitude "))) { - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join(by = join_vars, location_coordinates) } else { - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::mutate( location_name = NA_character_, `latitude (deg)` = NA_character_, @@ -52,7 +52,7 @@ join_location_coordinates <- function(austraits) { ) } - austraits + database } @@ -60,7 +60,7 @@ join_location_coordinates <- function(austraits) { #' @description Function to merge metadata from the taxa table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param vars Columns from the taxa table to be joined to the traits table, defaulting to c("family", "genus", "taxon_rank", "establishment_means"). #' #' @return traits.build list object, but with additional fields (columns) for the specified variables from the taxa table appended to the traits table. @@ -79,27 +79,27 @@ join_location_coordinates <- function(austraits) { #' @examples #' \dontrun{ #' #Append taxonomic details -#' (austraits %>% join_taxa)$traits +#' (database %>% join_taxa)$traits #' } -join_taxa <- function(austraits, +join_taxa <- function(database, vars = c("family", "genus", "taxon_rank", "establishment_means")) { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # If all columns to be added, create `vars` vector if (vars[1] == "all" & length(vars == 1)){ - vars <- names(austraits$taxa) + vars <- names(database$taxa) } # Join selected columns to traits table - austraits$traits <- - austraits$traits %>% - dplyr::left_join(by="taxon_name", austraits$taxa %>% dplyr::select("taxon_name", tidyselect::any_of(vars))) + database$traits <- + database$traits %>% + dplyr::left_join(by="taxon_name", database$taxa %>% dplyr::select("taxon_name", tidyselect::any_of(vars))) - austraits + database } @@ -107,7 +107,7 @@ join_taxa <- function(austraits, #' #' @description Function to merge metadata from the taxonomic_updates table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param vars Columns from the taxa table to be joined to the traits table, defaulting to c("aligned_name"). #' #' @return traits.build list object, but with additional fields (columns) for the specified variables from the taxonomic_updates table appended to the traits table. @@ -126,36 +126,36 @@ join_taxa <- function(austraits, #' @examples #' \dontrun{ #' #Append taxonomic update details -#' (austraits %>% join_taxonomic_updates)$traits +#' (database %>% join_taxonomic_updates)$traits #' } -join_taxonomic_updates <- function(austraits, vars = c("aligned_name")) { +join_taxonomic_updates <- function(database, vars = c("aligned_name")) { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # If all columns to be added, create `vars` vector if (vars[1] == "all" & length(vars == 1)){ - vars <- names(austraits$taxonomic_updates) + vars <- names(database$taxonomic_updates) } # Join selected columns to traits table - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join(by = c("taxon_name", "dataset_id", "original_name"), - austraits$taxonomic_updates %>% + database$taxonomic_updates %>% dplyr::select("taxon_name", "dataset_id", "original_name", tidyselect::any_of(vars))) - austraits + database } #' @title Joining methodological information to traits table #' #' @description Function to merge metadata from the methods table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param vars Columns from the taxa table to be joined to the traits table, defaulting to c("methods"). #' #' @return traits.build list object, but with additional fields (columns) for the specified variables from the methods table appended to the traits table. @@ -173,30 +173,30 @@ join_taxonomic_updates <- function(austraits, vars = c("aligned_name")) { #' #' @examples #' \dontrun{ -#' (austraits %>% join_methods)$traits +#' (database %>% join_methods)$traits #' } -join_methods <- function(austraits, vars = c("methods")) { +join_methods <- function(database, vars = c("methods")) { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # If all columns to be added, create `vars` vector if (vars[1] == "all" & length(vars == 1)){ - vars <- names(austraits$methods) + vars <- names(database$methods) } # Join selected columns to traits table - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join(by=c("dataset_id", "trait_name", "method_id"), - austraits$methods %>% + database$methods %>% dplyr::select(c("dataset_id", "trait_name", "method_id"), tidyselect::any_of(vars)) %>% dplyr::distinct() ) - austraits + database } @@ -204,7 +204,7 @@ join_methods <- function(austraits, vars = c("methods")) { #' #' @description Function to merge metadata from the data contributors table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param format Specifies whether metadata from the contributors table is output in a human readable format ("single_column_pretty"; default) or using json syntax ("single_column_json"). #' @param vars Columns from the taxa table to be joined to the traits table, defaulting to all columns (vars = "all"). #' @@ -226,25 +226,25 @@ join_methods <- function(austraits, vars = c("methods")) { #' (database %>% join_contributors(format = "single_column_pretty", #' vars = c("last_name", "first_name", "ORCID")))$traits #' } -join_contributors <- function(austraits, +join_contributors <- function(database, format = "single_column_pretty", vars = "all") { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # Work out which vars to retain and create a dataframe for compacting if (vars[1] == "all") { - contributors_tmp <- austraits$contributors + contributors_tmp <- database$contributors } else { # Create vector that is combination of selected columns and required columns vars_tmp <- c("dataset_id", "last_name", "given_name", vars) # Determine which columns aren't wanted - vars_remove <- setdiff(names(austraits$contributors), vars_tmp) + vars_remove <- setdiff(names(database$contributors), vars_tmp) # Remove unwanted columns from contributors dataframe - contributors_tmp <- austraits$contributors %>% dplyr::select(-dplyr::any_of(vars_remove)) + contributors_tmp <- database$contributors %>% dplyr::select(-dplyr::any_of(vars_remove)) } # Different options for how data are compacted and joined depending on `format` argument @@ -279,17 +279,17 @@ join_contributors <- function(austraits, } else if (format == "single_column_json") { compacted_contributors_column <- - contributors_tmp |> - tidyr::nest(-dplyr::all_of("dataset_id")) |> - dplyr::mutate(data_contributors = purrr::map_chr(data, jsonlite::toJSON)) |> - dplyr::select(-dplyr::any_of("data")) |> + contributors_tmp %>% + tidyr::nest(-dplyr::all_of("dataset_id")) %>% + dplyr::mutate(data_contributors = purrr::map_chr(data, jsonlite::toJSON)) %>% + dplyr::select(-dplyr::any_of("data")) %>% dplyr::ungroup() } - austraits$traits <- austraits$traits %>% + database$traits <- database$traits %>% dplyr::left_join(by = c("dataset_id"), compacted_contributors_column) - austraits + database } @@ -297,7 +297,7 @@ join_contributors <- function(austraits, #' #' @description Function to merge metadata from the locations table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param format Specifies whether metadata from the locations is output in a human readable format ("single_column_pretty"; default), with each location property added as a separate column ("many_columns") or using json syntax ("single_column_json"). #' @param vars Location properties for which data is to be appended to the traits table, defaulting to all location properties (vars = "all"). #' @@ -318,20 +318,20 @@ join_contributors <- function(austraits, #' \dontrun{ #' (database %>% join_location_properties(format = "single_column_pretty", vars = "all"))$traits #' } -join_location_properties <- function(austraits, +join_location_properties <- function(database, format = "single_column_pretty", vars = "all") { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # If all location properties to be added, create `vars` vector that is unique list # of location properties in the database if (vars[1] == "all") { - vars_tmp <- austraits$locations %>% + vars_tmp <- database$locations %>% dplyr::distinct(location_property) %>% dplyr::filter(!location_property %in% c("latitude (deg)", "longitude (deg)")) @@ -342,12 +342,12 @@ join_location_properties <- function(austraits, vars <- setdiff(vars, c("latitude (deg)", "longitude (deg)")) locations <- - austraits$locations %>% + database$locations %>% dplyr::filter(location_property %in% vars) # Variables to join_ by depends on if location_name already in traits table # from joining coordinates for instances - join_vars <- intersect(names(austraits$traits), c("dataset_id", "location_id", "location_name")) + join_vars <- intersect(names(database$traits), c("dataset_id", "location_id", "location_name")) # Different options for how data are compacted and joined depending on `format` argument if (format == "many_columns") { @@ -359,8 +359,8 @@ join_location_properties <- function(austraits, tidyr::pivot_wider(names_from = location_property) # Join locations, based on appropriate columns - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join(by = join_vars, locations) } else if (format == "single_column_pretty") { @@ -376,32 +376,32 @@ join_location_properties <- function(austraits, dplyr::ungroup() %>% dplyr::distinct() - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join(by = join_vars, compacted_locations_column) } else if (format == "single_column_json") { compacted_locations_column <- - locations |> - tidyr::nest(data = -dplyr::all_of(c("dataset_id", "location_id"))) |> - dplyr::mutate(location_properties = purrr::map_chr(data, jsonlite::toJSON)) |> - dplyr::select(-dplyr::any_of("data")) |> + locations %>% + tidyr::nest(data = -dplyr::all_of(c("dataset_id", "location_id"))) %>% + dplyr::mutate(location_properties = purrr::map_chr(data, jsonlite::toJSON)) %>% + dplyr::select(-dplyr::any_of("data")) %>% dplyr::ungroup() - austraits$traits <- austraits$traits %>% + database$traits <- database$traits %>% dplyr::left_join(by = join_vars, compacted_locations_column) } - austraits + database } #' @title Joining context properties to traits table #' #' @description Function to merge metadata from the contexts table of a traits.build database into the core traits table. #' -#' @param austraits traits.build database +#' @param database traits.build database (list object) #' @param format Specifies whether metadata from the contexts is output in a human readable format ("single_column_pretty"; default), with each context property added as a separate column ("many_columns") or using json syntax ("single_column_json"). #' @param vars Location properties for which data is to be appended to the traits table, defaulting to all context properties (vars = "all"). #' @param include_description A logical indicating whether to include (TRUE) or omit (FALSE) the context_property descriptions. @@ -424,25 +424,25 @@ join_location_properties <- function(austraits, #' (database %>% join_context_properties( #' format = "many_columns", vars = "all", include_description = TRUE))$traits #' } -join_context_properties <- function(austraits, +join_context_properties <- function(database, format = "single_column_pretty", vars = "all", include_description = TRUE) { # Check compatibility - if(!check_compatibility(austraits)){ - function_not_supported(austraits) + if(!check_compatibility(database)){ + function_not_supported(database) } # If all context properties to be added, create `vars` vector that is unique list # of context properties in the database if (vars[1] == "all") { - vars <- austraits$contexts$context_property %>% unique() + vars <- database$contexts$context_property %>% unique() } # Create dataframe of contexts to use & add `context_property:` to context properties contexts_tmp <- - austraits$contexts %>% + database$contexts %>% dplyr::filter(context_property %in% vars) %>% dplyr::mutate(context_property = paste0(category, ": ", context_property)) @@ -481,13 +481,13 @@ join_context_properties <- function(austraits, } else if (format == "single_column_json") { contexts_tmp <- - contexts_tmp |> - tidyr::separate_longer_delim(link_vals, ", ") |> - dplyr::distinct() |> - dplyr::mutate(description = ifelse(!is.na(description) & include_description, description, NA)) |> - tidyr::nest(data = -dplyr::all_of(c("dataset_id", "link_id", "link_vals"))) |> - dplyr::mutate(value = purrr::map_chr(data, jsonlite::toJSON)) |> - dplyr::select(-dplyr::any_of("data")) |> + contexts_tmp %>% + tidyr::separate_longer_delim(link_vals, ", ") %>% + dplyr::distinct() %>% + dplyr::mutate(description = ifelse(!is.na(description) & include_description, description, NA)) %>% + tidyr::nest(data = -dplyr::all_of(c("dataset_id", "link_id", "link_vals"))) %>% + dplyr::mutate(value = purrr::map_chr(data, jsonlite::toJSON)) %>% + dplyr::select(-dplyr::any_of("data")) %>% dplyr::ungroup() pivot <- FALSE @@ -496,7 +496,7 @@ join_context_properties <- function(austraits, stop("format not supported: ", format) } - # Merge contexts to austraits$traits + # Merge contexts to database$traits # Defines a function to further reformat specific columns of the context table reformat_contexts <- function(data, context_id, pivot) { @@ -521,8 +521,8 @@ join_context_properties <- function(austraits, } - austraits$traits <- - austraits$traits %>% + database$traits <- + database$traits %>% dplyr::left_join( by = c("dataset_id", "treatment_context_id"), reformat_contexts(contexts_tmp, "treatment_context_id", pivot) @@ -544,7 +544,7 @@ join_context_properties <- function(austraits, reformat_contexts(contexts_tmp, "method_context_id", pivot) ) - austraits + database } diff --git a/R/load_austraits.R b/R/load_austraits.R index e016865..020fd06 100644 --- a/R/load_austraits.R +++ b/R/load_austraits.R @@ -62,7 +62,7 @@ load_austraits <- function(doi = NULL, version = NULL, path = "data/austraits", version_name <- paste0("v", version) # Getting specific version - id <- ret[which(ret$version == version), "id"] |> as.character() + id <- ret[which(ret$version == version), "id"] %>% as.character() target <- res$hits$hits$files[[version_name]] @@ -119,15 +119,15 @@ load_json <- function(path, update){ create_metadata <- function(res){ # Version table - ret <- res$hits$hits$metadata |> - dplyr::select(tidyselect::all_of(c("publication_date", "doi", "version"))) |> - dplyr::mutate(version = gsub("v", "", version) |> numeric_version(), + ret <- res$hits$hits$metadata %>% + dplyr::select(tidyselect::all_of(c("publication_date", "doi", "version"))) %>% + dplyr::mutate(version = gsub("v", "", version) %>% numeric_version(), id = stringr::str_remove_all(doi, stringr::fixed("10.5281/zenodo.")) - )|> # set as numeric version for easier filtering - dplyr::filter(version >= "3.0.2") |> # exclude everything pre 3.0.2 + )%>% # set as numeric version for easier filtering + dplyr::filter(version >= "3.0.2") %>% # exclude everything pre 3.0.2 dplyr::mutate(version = as.character(version), - publication_date = lubridate::ymd(publication_date)) |> # change back as character - dplyr::tibble() |> + publication_date = lubridate::ymd(publication_date)) %>% # change back as character + dplyr::tibble() %>% dplyr::arrange(dplyr::desc(publication_date)) ret @@ -228,10 +228,10 @@ get_version_latest <- function(path = "data/austraits", update = TRUE){ metadata <- create_metadata(res) # Sort old to new - metadata <- metadata |> + metadata <- metadata %>% dplyr::arrange(dplyr::desc(publication_date)) # Grab the first version - dplyr::first(metadata$version) |> as.character() + dplyr::first(metadata$version) %>% as.character() } diff --git a/R/lookup.R b/R/lookup_.R similarity index 70% rename from R/lookup.R rename to R/lookup_.R index 382cc29..3c0c1e6 100644 --- a/R/lookup.R +++ b/R/lookup_.R @@ -1,6 +1,6 @@ #' Look up a particular trait term #' -#' @param austraits austraits list +#' @param database traits.build database (list object) #' @param term character string for trait search term #' #' @return vector containing traits that contains search term @@ -8,11 +8,11 @@ #' #' @examples #' \dontrun{ -#' austraits %>% lookup_trait("leaf") %>% extract_trait(austraits, .) +#' austraits %>% lookup_trait("leaf") %>% extract_trait(database = austraits, .) #' } -lookup_trait <- function(austraits, term){ +lookup_trait <- function(database, term){ - all_traits <- austraits$traits$trait_name %>% unique() + all_traits <- database$traits$trait_name %>% unique() ret <- stringr::str_subset(all_traits, term) @@ -30,7 +30,7 @@ lookup_trait <- function(austraits, term){ #' Look up location properties that contain a specific search term. #' #' -#' @param austraits austraits list +#' @param database traits.build database (list object) #' @param term character string for location property search term #' #' @return vector containing location properties that contains search term @@ -40,9 +40,9 @@ lookup_trait <- function(austraits, term){ #' \dontrun{ #' austraits %>% lookup_location_property("soil") #' } -lookup_location_property <- function(austraits, term){ +lookup_location_property <- function(database, term){ - all_location_properties <- austraits$locations$location_property %>% unique() + all_location_properties <- database$locations$location_property %>% unique() ret <- stringr::str_subset(all_location_properties, term) @@ -60,7 +60,7 @@ lookup_location_property <- function(austraits, term){ #' Look up context properties that contain a specific search term. #' #' -#' @param austraits austraits list +#' @param database traits.build database (list object) #' @param term character string for context property search term #' #' @return vector containing context properties that contains search term @@ -70,9 +70,9 @@ lookup_location_property <- function(austraits, term){ #' \dontrun{ #' austraits %>% lookup_context_property("temperature") #' } -lookup_context_property <- function(austraits, term){ +lookup_context_property <- function(database, term){ - all_context_properties <- austraits$contexts$context_property %>% unique() + all_context_properties <- database$contexts$context_property %>% unique() ret <- stringr::str_subset(all_context_properties, term) diff --git a/R/plot_locations.R b/R/plot_locations.R index 17fdbde..0f69930 100644 --- a/R/plot_locations.R +++ b/R/plot_locations.R @@ -1,6 +1,6 @@ #' @title Produce location maps of trait values #' @description Plot location where trait data was collected from -#' @param aus_traits austraits object OR traits table. Note location details must be joined. See join_location_coordinates and examples +#' @param database traits.build database OR traits table from a traits.build database. Note location details must be joined. See join_location_coordinates and examples #' @param feature grouping/classification categories e.g trait_name, collection_type for <= v3.0.2, basis of record for >3.0.2 #' @param ... arguments passed to ggplot() #' @author Dony Indiarto - d.indiarto@student.unsw.edu.au @@ -18,22 +18,22 @@ #' @export -plot_locations <- function(aus_traits, feature="trait_name", ...){ +plot_locations <- function(database, feature="trait_name", ...){ # Check if traits.build object or the traits table # If traits.build, check if traits table contains coordinate cols - if( is.null(dim(aus_traits)) ){ + if( is.null(dim(database)) ){ # Extract traits table if needed - traits <- get_traits_table(aus_traits) + traits <- get_traits_table(database) if( length(stringr::str_which(names(traits), "(deg)")) < 2 ){ cli::cli_alert_info("Coordinate columns were not detected, joining location tables now.") - aus_traits <- aus_traits |> join_location_coordinates() - traits <- get_traits_table(aus_traits) + database <- database %>% join_location_coordinates() + traits <- get_traits_table(database) } } else { - traits <- aus_traits #If not traits.build, assign traits table as traits + traits <- database #If not traits.build, assign traits table as traits # Check if traits contains coordinate cols in traits table if( length(stringr::str_which(names(traits), "(deg)")) < 2 ) @@ -45,15 +45,15 @@ plot_locations <- function(aus_traits, feature="trait_name", ...){ #' Location plot for AusTraits versions > 3.0.2 #' @noRd -plot_locations2 <- function(aus_traits, feature, ...){ +plot_locations2 <- function(database, feature, ...){ au_map <- australia_map_raster %>% dplyr::mutate(australia = as.factor(australia)) #Create site data sites <- - aus_traits |> - dplyr::select(!!feature, tidyselect::any_of(c("site_name", "location_name", "latitude (deg)", "longitude (deg)"))) |> - tidyr::drop_na() |> + database %>% + dplyr::select(!!feature, tidyselect::any_of(c("site_name", "location_name", "latitude (deg)", "longitude (deg)"))) %>% + tidyr::drop_na() %>% dplyr::mutate(dplyr::across(c("longitude (deg)","latitude (deg)"), as.numeric)) %>% dplyr::filter( `latitude (deg)` > (-45), `latitude (deg)` < (-9.5), @@ -101,21 +101,21 @@ plot_locations2 <- function(aus_traits, feature, ...){ #' @description `r lifecycle::badge('deprecated')` #' #'Plot location where trait data was collected from -#' @param traits traits table with site details appended. See join_location_coordinates and examples +#' @param trait_data traits table in a traits.build database with site details appended. See join_location_coordinates and examples #' @param feature grouping/classification categories e.g trait_name, collection_type for <= v3.0.2 #' @param ... arguments passed to ggplot() #' @author Dony Indiarto - d.indiarto@student.unsw.edu.au #' @return ggplot of sites #' @export -plot_site_locations <- function(traits, feature="trait_name", ...){ +plot_site_locations <- function(trait_data, feature="trait_name", ...){ # Extract function name function_name <- as.character(sys.calls()[[1]])[1] # Determine if traits table or traits.build object - if( is.null(dim(traits))){ + if( is.null(dim(trait_data))){ # Extract AusTraits version - AusTraits_version <- print_version(aus_traits) + AusTraits_version <- print_version(database) } else AusTraits_version <- "< 5.0.0" diff --git a/R/plot_trait_distribution_beeswarm.R b/R/plot_trait_distribution_beeswarm.R index 16881a4..7c5eea6 100644 --- a/R/plot_trait_distribution_beeswarm.R +++ b/R/plot_trait_distribution_beeswarm.R @@ -1,11 +1,11 @@ #' @title Beeswarm Trait distribution #' @description Plots distribution of trait values by a grouping variable using ggbeeswarm package #' -#' @param austraits austraits data object +#' @param database traits.build database (list object) #' @param trait_name Name of trait to plot #' @param y_axis_category One of `dataset_id`, `family` -#' @param highlight specify a group to highlight -#' @param hide_ids add label on y_axis? +#' @param highlight Specify a group to highlight +#' @param hide_ids Logical for whether to add a label on y_axis? #' #' @export #' @@ -17,21 +17,21 @@ #' @export # -plot_trait_distribution_beeswarm <- function(austraits, +plot_trait_distribution_beeswarm <- function(database, trait_name, y_axis_category, - highlight=NA, + highlight = NA, hide_ids = FALSE) { # Check compatability - status <- check_compatibility(austraits) + status <- check_compatibility(database) # If compatible if(!status) { - function_not_supported(austraits) + function_not_supported(database) } # Subset data to this trait - austraits_trait <- extract_trait(austraits, trait_name) + database_trait <- extract_trait(database, trait_name) my_shapes <- c("_min" = 60, "_mean" = 16, "_max" = 62, "unknown" = 18) @@ -44,10 +44,10 @@ plot_trait_distribution_beeswarm <- function(austraits, factor(p, levels=names(my_shapes)) } - tax_info <- austraits_trait$taxa %>% dplyr::select(taxon_name, family) + tax_info <- database_trait$taxa %>% dplyr::select(taxon_name, family) data <- - austraits_trait$traits %>% + database_trait$traits %>% dplyr::mutate(shapes = as_shape(value_type)) %>% dplyr::left_join(by = "taxon_name", tax_info) %>% dplyr::mutate(value = as.numeric(value)) @@ -79,8 +79,8 @@ plot_trait_distribution_beeswarm <- function(austraits, } - vals <- list(minimum = purrr::pluck(austraits_trait, "definitions", trait_name, "allowed_values_min"), - maximum = purrr::pluck(austraits_trait, "definitions", trait_name, "allowed_values_max")) + vals <- list(minimum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_min"), + maximum = purrr::pluck(database_trait, "definitions", trait_name, "allowed_values_max")) range <- (vals$maximum/vals$minimum) diff --git a/R/print.austraits.R b/R/print.austraits.R index 2a83330..58f14a2 100644 --- a/R/print.austraits.R +++ b/R/print.austraits.R @@ -1,19 +1,19 @@ #' @title Generic for outputting a nice summary for austraits objects #' #' @name print.austraits -#' @param x austraits list object +#' @param database traits.build database #' @param \dots passed to print #' #' @return nicely printed table #' @export -print.austraits <- function(x, ...){ +print.austraits <- function(database, ...){ # Setting up - version <- x$build_info$version %>% as.character() - nrecords <- nrow(x$traits) - nspecies <- unique(x$traits$taxon_name) %>% length() - ntraits <- unique(x$traits$trait_name) %>% length() + version <- database$build_info$version %>% as.character() + nrecords <- nrow(database$traits) + nspecies <- unique(database$traits$taxon_name) %>% length() + ntraits <- unique(database$traits$trait_name) %>% length() cat("This is version", version, @@ -26,7 +26,7 @@ print.austraits <- function(x, ...){ if(package_version(version) <= '3.0.2'){ cat("\nThis object is a 'list' with the following components:\n\n", - x$definitions$austraits$elements %>% + database$definitions$austraits$elements %>% purrr::map(~.x[["description"]]) %>% as.vector() %>% sprintf("- `%s`: %s", names(.), .) %>% @@ -34,7 +34,7 @@ print.austraits <- function(x, ...){ ) } else{ cat("\nThis object is a 'list' with the following components:\n\n", - x$schema$austraits$elements %>% + database$schema$austraits$elements %>% purrr::map(~.x[["description"]]) %>% as.vector() %>% sprintf("- `%s`: %s", names(.), .) %>% diff --git a/R/seperate_trait_values.R b/R/separate_trait_values.R similarity index 78% rename from R/seperate_trait_values.R rename to R/separate_trait_values.R index 297df9e..4886f1c 100644 --- a/R/seperate_trait_values.R +++ b/R/separate_trait_values.R @@ -2,23 +2,23 @@ #' #' @description This function reverts the action of bind_trait_values. #' This function separates values that were concatenated so that studies that have multiple observations for a given trait will have seperate row for each observation. -#' @usage separate_trait_values(data, definitions) -#' @param data The trait data frame generated from austraits - see example +#' @usage separate_trait_values(trait_data, definitions) +#' @param trait_data The traits table in a traits.build database - see example #' @param definitions The austraits definitions data frame #' @return trait tibble #' @examples #' \dontrun{ -#' traits <- austraits$traits %>% +#' trait_data <- austraits$traits %>% #' dplyr::filter(dataset_id == "Falster_2005_1") -#' traits -#' traits_bind <- bind_trait_values(traits) +#' trait_data +#' traits_bind <- bind_trait_values(trait_data) #' separate_trait_values(traits_bind) #' } #' @author Daniel Falster - daniel.falster@unsw.edu.au #' @export #' -separate_trait_values <- function(data, definitions) { +separate_trait_values <- function(trait_data, definitions) { separate_x <- function(x) strsplit(x, "--")[[1]] @@ -34,15 +34,15 @@ separate_trait_values <- function(data, definitions) { } # record the number of values in each row of data - data$n_vals <- 1 + stringr::str_count(data$value_type, "--") + trait_data$n_vals <- 1 + stringr::str_count(trait_data$value_type, "--") # separate out those rows requiring no modification - out_1 <- data %>% + out_1 <- trait_data %>% dplyr::filter(n_vals == 1) - if (nrow(dplyr::filter(data, n_vals > 1)) > 0) { + if (nrow(dplyr::filter(trait_data, n_vals > 1)) > 0) { # separate out those rows requiring modification & modify - out_2 <- data %>% + out_2 <- trait_data %>% dplyr::filter(n_vals > 1) %>% dplyr::group_split(stringr::str_c(dataset_id, observation_id, trait_name, method_id, method_context_id, repeat_measurements_id, sep = " ")) %>% lapply(separate_values_worker) %>% diff --git a/R/summarise_austraits.R b/R/summarise_austraits.R index 0ea1bbf..519b50d 100644 --- a/R/summarise_austraits.R +++ b/R/summarise_austraits.R @@ -1,38 +1,38 @@ #' @title Summarise counts for a particular variable of interest #' #' @name summarise_austraits -#' @param austraits A large list of tibbles built from austraits +#' @param database traits.build database (list object) #' @param var variable you use wish to see summary of (trait_name, genus, family) #' #' @return dataframe of unique levels of variable with counts and percentage #' @export #' @examples #' \dontrun{ -#' summarise_austraits(austraits, "trait_name") -#' summarise_austraits(austraits, "family") +#' summarise_austraits(database = austraits, "trait_name") +#' summarise_austraits(database = austraits, "family") #' } -summarise_austraits <- function(austraits, var){ +summarise_austraits <- function(database, var){ if(!var %in% c("trait_name", "family", "genus")){ stop(paste0("Print summary for ", var, " has not been implemented! see examples)")) } switch(var, - trait_name = summarise_austraits_traits(austraits, var), - genus = summarise_austraits_taxa(austraits, var), - family = summarise_austraits_taxa(austraits, var) + trait_name = summarise_austraits_traits(database, var), + genus = summarise_austraits_taxa(database, var), + family = summarise_austraits_taxa(database, var) ) } #' @noRd #' @keywords internal -summarise_austraits_traits <-function(austraits, var) { +summarise_austraits_traits <-function(database, var) { ret <- - austraits[["traits"]] %>% + database[["traits"]] %>% dplyr::pull({{var}}) %>% sort() %>% janitor::tabyl() @@ -46,7 +46,7 @@ summarise_austraits_traits <-function(austraits, var) { percent_total = signif(percent, 3), percent = NULL) # Summary statistics - sum_stats <- austraits[["traits"]] %>% + sum_stats <- database[["traits"]] %>% dplyr::group_by(trait_name) %>% dplyr::summarise(n_dataset = length(unique(dataset_id)), n_taxa = length(unique(taxon_name))) @@ -54,19 +54,19 @@ summarise_austraits_traits <-function(austraits, var) { ret <- dplyr::left_join(ret, sum_stats, by = "trait_name") # Organise - ret %>% dplyr::select(1, dplyr::starts_with("n_"), percent_total) |> tibble::tibble() + ret %>% dplyr::select(1, dplyr::starts_with("n_"), percent_total) %>% tibble::tibble() } #' @noRd #' @keywords internal -summarise_austraits_taxa <-function(austraits, var) { +summarise_austraits_taxa <-function(database, var) { #Join taxonomic info - austraits <- austraits %>% join_taxa() + database <- database %>% join_taxa() # Create table - ret <- austraits[["traits"]] %>% + ret <- database[["traits"]] %>% dplyr::pull(var) %>% sort() %>% janitor::tabyl() @@ -84,7 +84,7 @@ summarise_austraits_taxa <-function(austraits, var) { # Summary statistics (https://stackoverflow.com/questions/55425976/use-quoted-variable-in-group-by-mutate-function-call) - sum_stats <- austraits[["traits"]] %>% + sum_stats <- database[["traits"]] %>% dplyr::group_by(!!rlang::sym(var)) %>% dplyr::summarise(n_dataset = length(unique(dataset_id)), n_taxa = length(unique(taxon_name))) @@ -92,6 +92,6 @@ summarise_austraits_taxa <-function(austraits, var) { ret <- dplyr::left_join(ret, sum_stats, by = var) # Organise - ret %>% dplyr::select(1, dplyr::starts_with("n_"), percent_total) |> tibble::tibble() + ret %>% dplyr::select(1, dplyr::starts_with("n_"), percent_total) %>% tibble::tibble() } diff --git a/R/summarise_trait_values.R b/R/summarise_trait_values.R index 912a3f7..b940e97 100644 --- a/R/summarise_trait_values.R +++ b/R/summarise_trait_values.R @@ -1,6 +1,6 @@ #' Compute mean trait values for studies that have multiple observations for a given trait #' -#' @param trait_data trait table for austraits list +#' @param trait_data the traits table in a traits.build database #' #' @return A reduced trait table, mean values are flagged with the suffix '_summarised' in value_type #' @export diff --git a/R/trait_pivot_wider.R b/R/trait_pivot_wider.R index 38af169..b506f99 100644 --- a/R/trait_pivot_wider.R +++ b/R/trait_pivot_wider.R @@ -6,7 +6,7 @@ #' #' The function austraits::trait_pivot_longer reverts the actions of this function. #' -#' @param aus_traits The traits table from traits.build database list object +#' @param database The traits tibble from a traits.build database #' @return traits.build traits table in wide format #' @details #' `trait_pivot_wider`` has been developed to pivot the traits table for a database build using the traits.build workflow. @@ -30,16 +30,16 @@ #' @author Daniel Falster - daniel.falster@unsw.edu.au #' @export -trait_pivot_wider <- function(aus_traits){ +trait_pivot_wider <- function(database){ # Extract traits table if needed - traits <- get_traits_table(aus_traits) + traits <- get_traits_table(database) # Check compatibility status <- check_traits_compatibility(traits) # If compatible if(!status){ - function_not_supported(aus_traits) + function_not_supported(database) } metadata_cols <- c("unit", "replicates", "measurement_remarks", "basis_of_value") diff --git a/R/utils.R b/R/utils.R index 3fe101b..508653a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -62,21 +62,21 @@ convert_list_to_df2 <- function(my_list, as_character = TRUE, on_empty = NA) { #' Notify user the function they are using is no longer support #' -#' @param austraits +#' @param database traits.build database (list object) #' -#' @return cli messaging about the function name, the version of austraits they are using and their next options +#' @return cli messaging about the function name, the version of AusTraits they are using and their next options #' @keywords internal #' @noRd -function_not_supported <- function(aus_traits, ...){ +function_not_supported <- function(database, ...){ # Extract function name function_name <- as.character(sys.calls()[[1]])[1] # Determine if traits table or traits.build object - if( is.null(dim(aus_traits))){ + if( is.null(dim(database))){ # Extract AusTraits version - AusTraits_version <- print_version(aus_traits) + AusTraits_version <- print_version(database) } else AusTraits_version <- "< 5.0.0" @@ -94,14 +94,14 @@ function_not_supported <- function(aus_traits, ...){ #' Retrieve traits table if user passes traits.build object. #' -#' @param aus_traits traits.build object or traits table +#' @param database traits.build database or traits table in a traits.build database -get_traits_table <- function(aus_traits){ - if( is.null(dim(aus_traits)) ){ - traits <- aus_traits$traits +get_traits_table <- function(database){ + if( is.null(dim(database)) ){ + traits <- database$traits } else{ - traits <- aus_traits + traits <- database } return(traits) @@ -112,8 +112,8 @@ get_traits_table <- function(aus_traits){ #' #' @description Helper function to convert character strings of NA into true NA #' @usage clean_NA(x) -#' @param data The trait data frame generated from austraits - see example -#' @param definitions The austraits definitions data frame +#' @param trait_data The traits table in a traits.build database +#' @param definitions The definitions tibble from a traits.build database #' @return vector where strings of NA are treated as true NA #' @examples #' \dontrun{ diff --git a/R/what_version.R b/R/what_version.R index 8d5eb25..9836ca7 100644 --- a/R/what_version.R +++ b/R/what_version.R @@ -1,12 +1,14 @@ -#' Determine whether version was pre or post 3.0.2 +#' Identify austraits.build or traits.build version +#' +#' @description Determine whether database version was built by austraits.build (AusTraits pre 5.0.0) or traits.build (AusTraits post 5.0.0) #' -#' @param austraits austraits list object +#' @param database traits.build database (list object) #' @return binary version for switch statements #' @noRd #' @keywords internal #' -what_version <- function(austraits){ - version <- austraits$build_info$version %>% as.character() +what_version <- function(database){ + version <- database$build_info$version %>% as.character() if(package_version(version) <= '3.0.2'){ ret_version <- "3-series-earlier" @@ -24,11 +26,11 @@ what_version <- function(austraits){ #' Print version of AusTraits object #' -#' @param austraits austraits list object +#' @param database traits.build database (list object) #' @return binary version for switch statements #' @noRd #' @keywords internal #' -print_version <- function(austraits){ - austraits$build_info$version %>% as.character() +print_version <- function(database){ + database$build_info$version %>% as.character() } \ No newline at end of file diff --git a/tests/testthat/test-extract_.R b/tests/testthat/test-extract_.R index e292035..da60770 100644 --- a/tests/testthat/test-extract_.R +++ b/tests/testthat/test-extract_.R @@ -9,7 +9,7 @@ genus = "Eucalyptus" taxon_name = "Banskia serrata" test_that("Error message is triggered", { - expect_error(austraits_5.0.0_lite |> extract_taxa()) + expect_error(austraits_5.0.0_lite %>% extract_taxa()) }) test_extract_error <- function(austraits){ diff --git a/tests/testthat/test-misc_bugs_.R b/tests/testthat/test-misc_bugs_.R index 4b2c3ff..7540191 100644 --- a/tests/testthat/test-misc_bugs_.R +++ b/tests/testthat/test-misc_bugs_.R @@ -13,13 +13,13 @@ test_that("Dataframe is extracted correctly", { dplyr::filter(trait_name == "lifespan") # Extract trait after - veronica |> extract_trait("lifespan") -> genus_first + veronica %>% extract_trait("lifespan") -> genus_first # Extract trait first - austraits |> extract_trait("lifespan") -> lifespan + austraits %>% extract_trait("lifespan") -> lifespan # Extract taxa after - lifespan |> extract_taxa(genus = "Veronica") -> trait_first + lifespan %>% extract_taxa(genus = "Veronica") -> trait_first expect_setequal(trait_first$traits$value, veronica_lifespan$value) expect_setequal(trait_first$traits$value, genus_first$traits$value) diff --git a/tests/testthat/test-plot_.R b/tests/testthat/test-plot_.R index 0c5c596..4a3da21 100644 --- a/tests/testthat/test-plot_.R +++ b/tests/testthat/test-plot_.R @@ -16,14 +16,14 @@ test_that("Function doesn't throw error", { test_non_compatibile <- function(austraits){ test_that("Throws correct errors for deprecated or non-compatible",{ - expect_error(austraits |> - extract_dataset("Falster_2003") |> - purrr::pluck("traits") |> plot_locations() + expect_error(austraits %>% + extract_dataset("Falster_2003") %>% + purrr::pluck("traits") %>% plot_locations() ) - expect_error(austraits |> - extract_dataset("Falster_2003") |> - purrr::pluck("traits") |> plot_lplot_site_locationsocations() + expect_error(austraits %>% + extract_dataset("Falster_2003") %>% + purrr::pluck("traits") %>% plot_lplot_site_locationsocations() ) }) } diff --git a/tests/testthat/test-trait_bind_sep.R b/tests/testthat/test-trait_bind_sep.R index d1d560f..6574996 100644 --- a/tests/testthat/test-trait_bind_sep.R +++ b/tests/testthat/test-trait_bind_sep.R @@ -2,7 +2,7 @@ dataset_id <- c("ABRS_1981") subset <- extract_dataset(austraits_5.0.0_lite, dataset_id = dataset_id) bounded <- bind_trait_values(subset$traits) -seperated <-separate_trait_values(data = bounded, austraits_5.0.0_lite$definitions) +seperated <-separate_trait_values(trait_data = bounded, austraits_5.0.0_lite$definitions) test_that("binding/seperating was successful", { expect_true(grep("--", bounded$value) %>% any()) diff --git a/tests/testthat/test-trait_pivot_.R b/tests/testthat/test-trait_pivot_.R index b95a19e..bd6595d 100644 --- a/tests/testthat/test-trait_pivot_.R +++ b/tests/testthat/test-trait_pivot_.R @@ -6,7 +6,7 @@ test_pivot_success <- function(austraits){ test_that("pivot on subset of data", { expect_silent( - wide_data <- austraits |> trait_pivot_wider() + wide_data <- austraits %>% trait_pivot_wider() ) expect_type(wide_data, "list") @@ -19,7 +19,7 @@ purrr::walk(inputs, test_that("Widen structure is expected", { - wide_data <- austraits_5.0.0_lite |> trait_pivot_wider() + wide_data <- austraits_5.0.0_lite %>% trait_pivot_wider() names(wide_data) #Checking if widened data has the same length as variables that we are spreading expect_gt(ncol(wide_data), ncol(austraits_5.0.0_lite$traits))