From db7264dba919c5982213bcf9816054c37bfcb09b Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Fri, 23 Feb 2024 16:35:15 +1100 Subject: [PATCH 1/6] Code to generate link in processing #87 --- R/galah_download.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/galah_download.R b/R/galah_download.R index 1bfd59c..117f00c 100644 --- a/R/galah_download.R +++ b/R/galah_download.R @@ -236,6 +236,9 @@ process_data <- function(data) { recordedBy, recordID ) |> + mutate(link = case_when(grepl("https", voucher_location) ~ voucher_location, + TRUE ~ paste0("https://biocache.ala.org.au/occurrences/", recordID)) + ) |> janitor::clean_names("title") } From d46dac3adb5265c06477452794cb14171d3dedc7 Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Wed, 28 Feb 2024 09:10:07 +1100 Subject: [PATCH 2/6] Renames Establishment means earlier in workflow to remove processing in server.R --- R/galah_download.R | 5 ++++- R/server.R | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/galah_download.R b/R/galah_download.R index 117f00c..0e8a27a 100644 --- a/R/galah_download.R +++ b/R/galah_download.R @@ -180,7 +180,6 @@ get_establishment_status <- function(ala_cleaned, taxon = taxon) { ala_cleaned$native_anywhere_in_aus <- "native" ala_cleaned$native_anywhere_in_aus[ala_cleaned$Species %in% c("Danaus plexippus", "Pieris rapae")] <- "introduced" - return(ala_cleaned) } if (!taxon %in% c("Cicadoidea", "Marsupialia", @@ -189,6 +188,10 @@ get_establishment_status <- function(ala_cleaned, taxon = taxon) { "Plantae")) { ala_cleaned$native_anywhere_in_aus <- "unknown" } + # Rename native_anywhere_in_aus + ala_cleaned <- dplyr::rename(ala_cleaned, + `Establishment means` = native_anywhere_in_aus) + return(ala_cleaned) } diff --git a/R/server.R b/R/server.R index 7f2ec68..acbb2dd 100644 --- a/R/server.R +++ b/R/server.R @@ -150,7 +150,7 @@ infinity_server <- function(...) { total_family <- length(unique(data$Family)) native <- - dplyr::filter(data, native_anywhere_in_aus == "native") + dplyr::filter(data, `Establishment means` == "native") if (nrow(native) > 0) total_native_species <- length(unique(native$Species)) else @@ -287,7 +287,7 @@ infinity_server <- function(...) { `Recorded by` = `Recorded by`[1] ), by = .(Species, - `Establishment means` = native_anywhere_in_aus, + `Establishment means`, `Voucher type` = `Voucher Type`)] @@ -365,8 +365,7 @@ infinity_server <- function(...) { ) data <- dplyr::rename(data, - 'Establishment means' = native_anywhere_in_aus, - 'Repository' = `Voucher Location`) + 'Repository' = `Voucher Location`) collectionDate_partial = lubridate::ymd_hms(data$`Collection Date`, tz = "UTC", quiet = TRUE) collectionDate_all = dplyr::if_else( is.na(collectionDate_partial), From aff1193b5dd24c7a07ea1f1394549afb8271696f Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Wed, 28 Feb 2024 09:30:55 +1100 Subject: [PATCH 3/6] Moved renaming of voucher location to repository to earlier workflow and out of server. Removed creation of URL from server and directly using link field. --- R/galah_download.R | 6 +++--- R/server.R | 20 ++++++++------------ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/R/galah_download.R b/R/galah_download.R index 0e8a27a..06d3b56 100644 --- a/R/galah_download.R +++ b/R/galah_download.R @@ -214,7 +214,7 @@ process_data <- function(data) { !stringr::str_detect(species, "spec.$") ) |> dplyr::mutate( - voucher_location = dplyr::if_else(!is.na(references), references, institutionCode), + repository = dplyr::if_else(!is.na(references), references, institutionCode), voucher_type = dplyr::case_when( basisOfRecord == "PRESERVED_SPECIMEN" ~ "Collection", !is.na(sounds) ~ "Audio", @@ -235,11 +235,11 @@ process_data <- function(data) { lat, long, voucher_type, - voucher_location, + repository, recordedBy, recordID ) |> - mutate(link = case_when(grepl("https", voucher_location) ~ voucher_location, + mutate(link = case_when(grepl("https", repository) ~ repository, TRUE ~ paste0("https://biocache.ala.org.au/occurrences/", recordID)) ) |> janitor::clean_names("title") diff --git a/R/server.R b/R/server.R index acbb2dd..cb83760 100644 --- a/R/server.R +++ b/R/server.R @@ -242,7 +242,7 @@ infinity_server <- function(...) { N = integer(0), Long = numeric(0), Lat = numeric(0), - `Voucher location` = character(0), + `Repository` = character(0), `Recorded by` = character(0), Native = character(0) ) @@ -266,21 +266,20 @@ infinity_server <- function(...) { }, Lat = Lat[1], Long = Long[1], - `Repository` = ifelse( - grepl("https", `Voucher Location`[1]), + Repository = ifelse( + grepl("https", Repository[1]), paste0( "", "iNat", "" ), paste0( "", - `Voucher Location`[1], + Repository[1], "" ) ), @@ -363,15 +362,12 @@ infinity_server <- function(...) { data$`Record Id` ) ) - data <- - dplyr::rename(data, - 'Repository' = `Voucher Location`) + collectionDate_partial = lubridate::ymd_hms(data$`Collection Date`, tz = "UTC", quiet = TRUE) collectionDate_all = dplyr::if_else( is.na(collectionDate_partial), lubridate::ymd(data$`Collection Date`, tz = "UTC", quiet = TRUE), - collectionDate_partial - ) + collectionDate_partial) data$`Collection Date` <- paste( lubridate::year(collectionDate_all), From 81199c241265637a94dd691dcbf18d25c8271389 Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Wed, 28 Feb 2024 13:34:24 +1100 Subject: [PATCH 4/6] Suppressed warnings from APCalign #87 --- R/galah_download.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/galah_download.R b/R/galah_download.R index 06d3b56..ea9c283 100644 --- a/R/galah_download.R +++ b/R/galah_download.R @@ -166,15 +166,15 @@ retrieve_data <- function(taxon, get_establishment_status <- function(ala_cleaned, taxon = taxon) { if (taxon == "Plantae") { resources <- APCalign::load_taxonomic_resources() + suppressWarnings( lookup <- APCalign::native_anywhere_in_australia(unique(ala_cleaned$Species), resources = resources) + ) lookup <- dplyr::rename(lookup, Species = species) ala_cleaned <- ala_cleaned |> dplyr::left_join(lookup, by = dplyr::join_by("Species")) - - return(ala_cleaned) } if (taxon %in% c("Cicadoidea", "Marsupialia", "Odonata", "Papilionoidea")) { ala_cleaned$native_anywhere_in_aus <- "native" From 1b09a03959afe287c65a0057549e9b07c0a753cd Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Wed, 28 Feb 2024 14:13:07 +1100 Subject: [PATCH 5/6] Removed URL creaton in downloadhandler --- R/server.R | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/R/server.R b/R/server.R index cb83760..ddbc6a0 100644 --- a/R/server.R +++ b/R/server.R @@ -353,16 +353,7 @@ infinity_server <- function(...) { }, content = function(file) { data <- intersect_data() - data$`Voucher Location` = ifelse( - grepl("https", data$`Voucher Location`), - data$`Voucher Location` - , - paste0( - "https://biocache.ala.org.au/occurrences/", - data$`Record Id` - ) - ) - + # Fixing the date collectionDate_partial = lubridate::ymd_hms(data$`Collection Date`, tz = "UTC", quiet = TRUE) collectionDate_all = dplyr::if_else( is.na(collectionDate_partial), From 2f6aafe77a60c8d1333054e83bec561d55d6c6fd Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Fri, 1 Mar 2024 10:46:50 +1100 Subject: [PATCH 6/6] Updated snapshot --- R/galah_download.R | 5 ++--- R/infinitylists-package.R | 5 ++++- tests/testthat/_snaps/galah_download.md | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/R/galah_download.R b/R/galah_download.R index ea9c283..622378a 100644 --- a/R/galah_download.R +++ b/R/galah_download.R @@ -189,8 +189,7 @@ get_establishment_status <- function(ala_cleaned, taxon = taxon) { ala_cleaned$native_anywhere_in_aus <- "unknown" } # Rename native_anywhere_in_aus - ala_cleaned <- dplyr::rename(ala_cleaned, - `Establishment means` = native_anywhere_in_aus) + ala_cleaned <- dplyr::rename(ala_cleaned,"Establishment means" = native_anywhere_in_aus) return(ala_cleaned) } @@ -239,7 +238,7 @@ process_data <- function(data) { recordedBy, recordID ) |> - mutate(link = case_when(grepl("https", repository) ~ repository, + dplyr::mutate(link = dplyr::case_when(grepl("https", repository) ~ repository, TRUE ~ paste0("https://biocache.ala.org.au/occurrences/", recordID)) ) |> janitor::clean_names("title") diff --git a/R/infinitylists-package.R b/R/infinitylists-package.R index 9c6f9a9..8b3f3ee 100644 --- a/R/infinitylists-package.R +++ b/R/infinitylists-package.R @@ -57,6 +57,9 @@ utils::globalVariables( "str_detect", "voucher_location", "voucher_type", - "write.csv" + "write.csv", + "Link", + "Repository", + "Establishment means" ) ) \ No newline at end of file diff --git a/tests/testthat/_snaps/galah_download.md b/tests/testthat/_snaps/galah_download.md index ead95fe..b23c5c4 100644 --- a/tests/testthat/_snaps/galah_download.md +++ b/tests/testthat/_snaps/galah_download.md @@ -3,16 +3,16 @@ Code odonata Output - # A tibble: 7 x 11 - Species Genus Family `Collection Date` Lat Long `Voucher Type` - - 1 Adversaeschna bre~ Adve~ Aeshn~ 1924-10-01 00:00:00 -33.9 151. Collection - 2 Diplacodes bipunc~ Dipl~ Libel~ 1924-02-23 00:00:00 -37.8 145. Collection - 3 Austrolestes leda Aust~ Lesti~ 1924-11-06 00:00:00 -28.7 152. Collection - 4 Synthemis tasmani~ Synt~ Synth~ 1924-01-01 00:00:00 -41.9 145. Collection - 5 Austroaeschna par~ Aust~ Telep~ 1924-02-01 00:00:00 -42.1 145. Collection - 6 Hemicordulia tau Hemi~ Cordu~ 1924-10-10 00:00:00 -28.7 152. Collection - 7 Synthemis tasmani~ Synt~ Synth~ 1924-01-01 00:00:00 -41.9 145. Collection - # i 4 more variables: `Voucher Location` , `Recorded by` , - # `Record Id` , native_anywhere_in_aus + # A tibble: 7 x 12 + Species Genus Family `Collection Date` Lat Long `Voucher Type` Repository + + 1 Advers~ Adve~ Aeshn~ 1924-10-01 00:00:00 -33.9 151. Collection AM + 2 Diplac~ Dipl~ Libel~ 1924-02-23 00:00:00 -37.8 145. Collection NMV + 3 Austro~ Aust~ Lesti~ 1924-11-06 00:00:00 -28.7 152. Collection QM + 4 Synthe~ Synt~ Synth~ 1924-01-01 00:00:00 -41.9 145. Collection QM + 5 Austro~ Aust~ Aeshn~ 1924-02-01 00:00:00 -42.1 145. Collection QM + 6 Hemico~ Hemi~ Cordu~ 1924-10-10 00:00:00 -28.7 152. Collection QM + 7 Synthe~ Synt~ Synth~ 1924-01-01 00:00:00 -41.9 145. Collection QM + # i 4 more variables: `Recorded by` , `Record Id` , Link , + # `Establishment means`