Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A generalised solution to deprecate switch functions #97

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
64db845
Trying out map for tests
fontikar Jan 12, 2023
7704303
Added version number to austraits_list_post
fontikar Jan 12, 2023
5e2e6a2
Added Wright_2019 in old rel test dataset so tests are consistent
fontikar Jan 12, 2023
426fc4d
Updated code to subset 4.0.0 from zenodo
fontikar Jan 12, 2023
b677567
Version testing for extract, and summarise_austriats
fontikar Jan 12, 2023
c2008c5
Combined extract_ tests and added version testing
fontikar Jan 12, 2023
5e47cfb
Version tests for join_
fontikar Jan 13, 2023
c0781b5
Version tests for widetable and renamed test files
fontikar Jan 13, 2023
50154e1
#60 fixed imports for pivot_wider, organised tests, currently not wor…
fontikar Jan 13, 2023
247db43
Minor naming adjustments in test
fontikar Jan 13, 2023
2b79ab5
Merge branch 'multi_tests' into develop: All possible tests is run th…
fontikar Jan 13, 2023
82a0f0f
Change some dependencies to imports
dfalster Jan 25, 2023
6e0cb08
Remove helper functions to vignettes
dfalster Jan 25, 2023
8f79aa6
Update deprecated functions
dfalster Jan 25, 2023
30d95cc
Restructure tests to run faster
dfalster Jan 25, 2023
9615ed0
Change GH actions triggers
dfalster Jan 25, 2023
87bdb95
ensure consistent ordering of rows
dfalster Jan 25, 2023
846ba84
Merge branch 'master' into develop
fontikar Oct 16, 2023
3564de0
bumped version number
fontikar Oct 16, 2023
4a534bf
Update to work with latest zenodo API (#81)
dfalster Oct 16, 2023
17de18c
Pulled files we want to develop from change-v5
fontikar Oct 19, 2023
f9c1666
Changes for v5 austraits.build (#78)
fontikar Nov 21, 2023
10791de
Bumped version number and updated news
fontikar Nov 21, 2023
32e5262
Added references to packages
fontikar Nov 21, 2023
a64a360
Updated version for GH steps
fontikar Nov 21, 2023
23a2f7a
Updated v number for GHA
fontikar Nov 21, 2023
147030b
Expanding testing suite to all 3 major versions of AusTraits (#86)
fontikar Nov 22, 2023
2bd66f1
Added codecov yml
fontikar Nov 22, 2023
cc8e8cf
Merge branch 'develop' of https://github.com/traitecoevo/austraits in…
fontikar Nov 22, 2023
d1c6f61
Setting limit for patch cov
fontikar Nov 22, 2023
91c94c4
Merge branch 'master' into develop
fontikar Nov 26, 2023
a541663
bumped version number for dev
fontikar Nov 26, 2023
277a7e5
API related packages to Suggests (#89)
fontikar Nov 27, 2023
9360930
Merge branch 'master' into develop
fontikar Sep 3, 2024
9d32105
Bumped version number
fontikar Sep 3, 2024
6928738
create new function `check_compatibility` (#95)
ehwenk Sep 4, 2024
d40ea94
Updated NEWS.md with check_compatibiltiy
fontikar Sep 4, 2024
85beb0a
Test deprecate for extract_dataset
fontikar Sep 5, 2024
46769f2
Added print_version and added dependency to CLI for nice messaging an…
fontikar Sep 5, 2024
01af2da
Updated documentation still undecided, and moved main function in script
fontikar Sep 5, 2024
e65eebd
Ignoring messages in check_compat for now
fontikar Sep 5, 2024
55405e3
Enabled markdown in roxygen and included example
fontikar Sep 5, 2024
0ae346f
Function to notifiy users of change in support #91
fontikar Sep 5, 2024
20322af
Updated NEWS
fontikar Sep 5, 2024
3a7c1c3
Tear down switch
fontikar Sep 5, 2024
35c4f67
Updating tests to accomodate tear down for extract_
fontikar Sep 5, 2024
ab07817
Added metadata list to extracted object
fontikar Sep 5, 2024
5d607eb
Removed switch just use if statement
fontikar Sep 5, 2024
e4cf1b9
Use abort instead of bullet
fontikar Sep 5, 2024
fe15fb4
Test passing for extract_
fontikar Sep 5, 2024
2c9eb3a
Fixed tests that used extract
fontikar Sep 5, 2024
50bd34f
Fixed tests that used extract
fontikar Sep 5, 2024
6e8748d
fix outdated functions
ehwenk Sep 5, 2024
ae89b15
still a bug...
ehwenk Sep 5, 2024
b01f944
Update test-trait_bind_sep.R
ehwenk Sep 6, 2024
3bd4942
Fix `bind_trait_values` and `separate_trait_values` (#99)
ehwenk Sep 6, 2024
c4108f0
Merge remote-tracking branch 'origin/fix-bind_-and-separate_' into sw…
fontikar Sep 6, 2024
4ba7a1d
Updated global variables and dependencies in tests
fontikar Sep 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: austraits
Title: Helpful functions to access, summarise and wrangle austraits data
Version: 2.2.3
Version: 3.0.0.9000
Authors@R:
c(person(given = "Daniel",
family = "Falster",
Expand All @@ -22,7 +22,7 @@ Encoding: UTF-8
Language: en
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Depends:
R (>= 4.0.0),
RefManageR
Expand All @@ -39,7 +39,9 @@ Imports:
utils,
magrittr,
janitor,
lifecycle
lifecycle,
tibble,
cli
Suggests:
ggplot2,
ggpointdensity,
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# austraits 2.2.1
# austraits 3.0.0.9000
- Updated dependencies, placing graphics related packages in Suggests
- Added internal function to check the compatibility of databases
- Added internal function notify users that some database versions will not be supported
- No longer support AusTraits version <5.0.0 in `extract_*` functions
4 changes: 3 additions & 1 deletion R/austraits-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ utils::globalVariables(c("..density..",
"x",
"y",
"publication_date",
"doi")
"doi",
"relation_type",
"identifier")
)
7 changes: 4 additions & 3 deletions R/bind_trait_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @examples
#' \dontrun{
#' traits <- austraits$traits %>%
#' dplyr::filter(dataset_id == "Falster_2005_1")
#' dplyr::filter(dataset_id == "ABRS_1981")
#' traits
#' traits_bind <- bind_trait_values(traits)
#' }
Expand All @@ -28,6 +28,7 @@ bind_trait_values <- function(trait_data) {
.data %>%
dplyr::mutate(value = bind_x(.data$value),
value_type = bind_x(value_type),
basis_of_value = bind_x(basis_of_value),
replicates = bind_x(replicates)) %>%
dplyr::filter(dplyr::row_number()==1)
)
Expand All @@ -36,8 +37,8 @@ bind_trait_values <- function(trait_data) {
}

trait_data %>%
dplyr::group_by(observation_id, trait_name) %>%
dplyr::group_by(dataset_id, observation_id, trait_name, method_id, method_context_id, repeat_measurements_id) %>%
bind_values_worker() %>%
dplyr::ungroup() %>%
dplyr::arrange(observation_id, trait_name, value_type)
dplyr::arrange(dataset_id, observation_id, trait_name, value_type, method_id, method_context_id, repeat_measurements_id)
}
41 changes: 41 additions & 0 deletions R/check_compatibility.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' @title Check compatibility
#' @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
#'
#' @return logical (T/F) output and messaging for uncompatible versions
#'
#' @examples
#' \dontrun{
#' check_compatibility(austraits)
#' }
#' @author Elizabeth Wenk - e.wenk@unsw.edu.au

check_compatibility <- function(austraits) {

if (is.null(austraits$metadata)) {

compatible <- FALSE

# message("You are working with AusTraits version 3.0 or earlier. \nThis database structure is unsupported by the current version of this package. \nPlease see https://github.com/traitecoevo/austraits for details on installing old versions of the package.")

} else {

compiled_by_traits.build <-
austraits$metadata$related_identifiers %>%
util_list_to_df2() %>%
filter(relation_type == "isCompiledBy", stringr::str_detect(identifier, "github.com/traitecoevo/traits.build"))

if(is.null(compiled_by_traits.build) | nrow(compiled_by_traits.build) > 0) {
compatible <- TRUE
} else{
compatible <- FALSE

# message("You are working with AusTraits version 4, which is unsupported by the current version of this package. \nPlease see https://github.com/traitecoevo/austraits for details on installing old versions of the package.")
}

}

invisible(compatible)

}
58 changes: 20 additions & 38 deletions R/extract_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param austraits - A large list of tibbles built from austraits
#' @param dataset_id - character string that matches a dataset_id in the data
#' @return A large list of tibbles containing all austraits information for one particular dataset
#'
#' @details `extract_dataset()` no longer supports AusTraits version <= 5.0.0, see [this page](https://github.com/traitecoevo/austraits) for details. `r lifecycle::badge("deprecated")`
#' @examples
#' \dontrun{
#' extract_dataset(austraits, "Falster_2003")
Expand All @@ -15,10 +15,14 @@


extract_dataset <- function(austraits, dataset_id) {

# Check compatability
status <- suppressMessages(check_compatibility(austraits))

# Switch for different versions
version <- what_version(austraits)

if(what_version(austraits) %in% c("4-series", "5-series")){
if(what_version(austraits) %in% "5-series" | status){
version <- "new"
} else
version <- "old"
Expand All @@ -29,43 +33,8 @@ extract_dataset <- function(austraits, dataset_id) {
)
}

#' @title Extract specific dataset from austraits object for versions <=3.0.2
#' @rdname extract_dataset
extract_dataset1 <- function(austraits, dataset_id){
austraits$taxonomic_updates <-
tidyr::separate_rows(austraits$taxonomic_updates, dataset_id, sep=" ")

ret <- list()
for(v in c("traits", "sites", "contexts", "methods", "excluded_data", "taxonomic_updates", "contributors"))
ret[[v]] <- austraits[[v]][ austraits[[v]][["dataset_id"]] %in% dataset_id,]
# NB: can't use dplyr::filter in the above as it doesn't behave when the variable name is the same as a column name

ret[["taxa"]] <- austraits[["taxa"]] %>% dplyr::filter(taxon_name %in% ret[["traits"]][["taxon_name"]])

ret[["definitions"]] <- austraits[["definitions"]]
ret[["build_info"]] <- austraits[["build_info"]]

keys <- dplyr::union(ret$methods$source_primary_key,
ret$methods$source_secondary_key %>% strsplit("; ") %>% unlist()) %>%
unique() %>% stats::na.omit() %>% as.character()

ret[["sources"]] <- austraits$sources[keys]

ret[["sources"]] <- austraits[["sources"]][keys]

assertthat::are_equal(sort(names(austraits)), sort(names(ret)))

ret[names(austraits)]

# Assign class
attr(ret, "class") <- "austraits"

ret
}


#' @title Extract specific dataset from austraits object for versions >3.0.2
#' @rdname extract_dataset
#' @noRd

extract_dataset2 <- function(austraits, dataset_id){
austraits$taxonomic_updates <-
Expand All @@ -82,6 +51,7 @@ extract_dataset2 <- function(austraits, dataset_id){
ret[["definitions"]] <- austraits[["definitions"]]
ret[["build_info"]] <- austraits[["build_info"]]
ret[["schema"]] <- austraits[["schema"]]
ret[["metadata"]] <- austraits[["metadata"]]

keys <- dplyr::union(ret$methods$source_primary_key,
ret$methods$source_secondary_key %>% strsplit("; ") %>% unlist()) %>%
Expand All @@ -100,3 +70,15 @@ extract_dataset2 <- function(austraits, dataset_id){

ret
}


#' @title Extract specific dataset from austraits object for versions <=3.0.2
#' @noRd

extract_dataset1 <- function(austraits, dataset_id){

function_not_supported(austraits)

}


87 changes: 7 additions & 80 deletions R/extract_taxa.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@
#' @export

extract_taxa <- function(austraits, family = NULL, genus = NULL, taxon_name = NULL){
# Switch for different versions
version <- what_version(austraits)
# Check compatability
status <- check_compatibility(austraits)

if(what_version(austraits) %in% c("4-series", "5-series")){
version <- "new"
# If compatible
if(status){
extract_taxa2(austraits, family, genus, taxon_name)
} else
version <- "old"

switch (version,
'new' = extract_taxa2(austraits, family, genus, taxon_name),
'old' = extract_taxa1(austraits, family, genus, taxon_name),
)
function_not_supported(austraits)
}


#'Extract taxa >3.0.2
#'Extract taxa for supported versions of databases
#' @noRd
#' @keywords internal
extract_taxa2 <- function(austraits, family = NULL, genus = NULL, taxon_name = NULL){
Expand Down Expand Up @@ -98,75 +94,6 @@ extract_taxa2 <- function(austraits, family = NULL, genus = NULL, taxon_name = N
}


#'Extract taxa <=3.0.2
#' @noRd
#' @keywords internal
extract_taxa1 <- function(austraits, family = NULL, genus = NULL, taxon_name = NULL){

ret <- austraits

if(missing(family) & missing(genus) & missing(taxon_name)){
abort("Either `family`, `genus` or `taxon_name`, must be supplied!")
}

if( ! is.null(family) ){
# Retrieving all taxon name that falls under family
target_in <- stringr::str_which(austraits$taxa$family, paste(family, collapse = "|"))
target_taxa <- austraits$taxa %>% dplyr::slice(target_in) %>% dplyr::pull(taxon_name)
}

if( ! is.null(genus) ){
# Retrieving all taxon name that falls under genus
target_in <- stringr::str_which(austraits$taxa$genus, paste(genus, collapse = "|"))
target_taxa <- austraits$taxa %>% dplyr::slice(target_in) %>% dplyr::pull(taxon_name)
}

if( ! is.null(taxon_name)){
target_taxa <- taxon_name
}

# Extract data for target_sp
ret[["traits"]] <- ret[["traits"]] %>%
dplyr::filter(taxon_name %in% target_taxa)

ids <- ret[["traits"]][["dataset_id"]] %>% unique() %>% sort()

ret[["sites"]] <- austraits[["sites"]] %>% dplyr::filter(site_name %in% ret[["traits"]][["site_name"]], dataset_id %in% ids)

ret[["contexts"]] <- austraits[["contexts"]] %>% dplyr::filter(context_name %in% ret[["traits"]][["context_name"]], dataset_id %in% ids)

ret[["taxa"]] <- austraits[["taxa"]] %>% dplyr::filter(taxon_name %in% ret[["traits"]][["taxon_name"]])

ret[["taxonomic_updates"]] <- austraits[["taxonomic_updates"]] %>% dplyr::filter(taxon_name %in% ret[["traits"]][["taxon_name"]])
# Fix formatting for dataset ids
ret$taxonomic_updates <-
tidyr::separate_rows(austraits$taxonomic_updates, dataset_id, sep=" ")

ret[["excluded_data"]] <- austraits[["excluded_data"]] %>% dplyr::filter(taxon_name %in% target_taxa)

ret[["contributors"]] <- austraits[["contributors"]] %>% dplyr::filter(dataset_id %in% ids)

ret[["methods"]] <- austraits[["methods"]] %>% dplyr::filter(dataset_id %in%ids)

ret[["definitions"]] <- austraits[["definitions"]]

ret[["build_info"]] <- austraits[["build_info"]]

# if numeric, convert to numeric
suppressWarnings(
ret[["traits"]][["value"]] <- ifelse(! is.na(ret[["traits"]][["unit"]]),
as.numeric(ret[["traits"]][["value"]]),
ret[["traits"]][["value"]])

)

# Assign class
attr(ret, "class") <- "austraits"

ret
}





Expand Down
Loading
Loading