Skip to content

Commit

Permalink
Extract from single table only (#121)
Browse files Browse the repository at this point in the history
*    extract_ functions can now work with a single table or an entire traits.build database; the single table can have any columns, any number of columns
*    required a tweak to check_compatibility to allow single tables to be declared compatible. A extra parameter was added that indicates if the incoming data is allowed to be a single table
*   lots of documentation that was supposed to be on the previous commit

Closes issue #120
  • Loading branch information
ehwenk authored Nov 13, 2024
1 parent 70e7671 commit 09f96f2
Show file tree
Hide file tree
Showing 36 changed files with 325 additions and 275 deletions.
2 changes: 1 addition & 1 deletion R/bind_databases.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#' @param database_1 List of traits.build databases to bind together
#'
#' @return Compiled database as a single large list
#' @importFrom rlang .data
Expand Down
39 changes: 24 additions & 15 deletions R/check_compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' @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 database traits.build database (list object)
#' @param single_table_allowed logical for when the input might be a single table instead of a complete database; defaults to FALSE
#'
#' @return logical (T/F) output and messaging for uncompatible versions
#'
Expand All @@ -11,28 +12,36 @@
#' }
#' @author Elizabeth Wenk - [email protected]

check_compatibility <- function(database) {
check_compatibility <- function(database, single_table_allowed = FALSE) {

if (is.null(database$metadata)) {
if (!is.null(dim(database)) & single_table_allowed == TRUE) {

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.")
compatible <- TRUE

} else {

compiled_by_traits.build <-
database$metadata$related_identifiers %>%
convert_list_to_df2() %>%
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) {
compatible <- TRUE
} else{
if (is.null(database$metadata)) {

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.")
# 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 <-
database$metadata$related_identifiers %>%
convert_list_to_df2() %>%
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) {
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.")
}

}

}
Expand Down
Loading

0 comments on commit 09f96f2

Please sign in to comment.