Skip to content

Commit

Permalink
standardise pipes
Browse files Browse the repository at this point in the history
Change all native pipes (|>) to %>% pipes
  • Loading branch information
ehwenk committed Nov 12, 2024
1 parent 79c9465 commit 871fac8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion R/check_compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions R/join_.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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 %>%
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions R/load_austraits.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

8 changes: 4 additions & 4 deletions R/plot_locations.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions R/summarise_austraits.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

}

0 comments on commit 871fac8

Please sign in to comment.