From 871fac846780b8a48971de31f67713a624d89c0e Mon Sep 17 00:00:00 2001 From: ehwenk Date: Wed, 13 Nov 2024 10:16:31 +1100 Subject: [PATCH] standardise pipes Change all native pipes (|>) to %>% pipes --- R/check_compatibility.R | 2 +- R/join_.R | 30 +++++++++++++++--------------- R/load_austraits.R | 20 ++++++++++---------- R/plot_locations.R | 8 ++++---- R/summarise_austraits.R | 4 ++-- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/R/check_compatibility.R b/R/check_compatibility.R index c30810a..d8e6d3a 100644 --- a/R/check_compatibility.R +++ b/R/check_compatibility.R @@ -24,7 +24,7 @@ check_compatibility <- function(database) { compiled_by_traits.build <- 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) { diff --git a/R/join_.R b/R/join_.R index e62f8c8..729a628 100644 --- a/R/join_.R +++ b/R/join_.R @@ -279,10 +279,10 @@ join_contributors <- function(database, } 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() } @@ -383,10 +383,10 @@ join_location_properties <- function(database, } 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() database$traits <- database$traits %>% @@ -481,13 +481,13 @@ join_context_properties <- function(database, } 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 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/plot_locations.R b/R/plot_locations.R index f246c82..0f69930 100644 --- a/R/plot_locations.R +++ b/R/plot_locations.R @@ -29,7 +29,7 @@ plot_locations <- function(database, feature="trait_name", ...){ if( length(stringr::str_which(names(traits), "(deg)")) < 2 ){ cli::cli_alert_info("Coordinate columns were not detected, joining location tables now.") - database <- database |> join_location_coordinates() + database <- database %>% join_location_coordinates() traits <- get_traits_table(database) } } else { @@ -51,9 +51,9 @@ plot_locations2 <- function(database, feature, ...){ #Create site data sites <- - database |> - 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), diff --git a/R/summarise_austraits.R b/R/summarise_austraits.R index b136bed..519b50d 100644 --- a/R/summarise_austraits.R +++ b/R/summarise_austraits.R @@ -54,7 +54,7 @@ summarise_austraits_traits <-function(database, 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 @@ -92,6 +92,6 @@ summarise_austraits_taxa <-function(database, 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() }