diff --git a/NEWS.md b/NEWS.md index e9e9d63..2c23014 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,4 +13,5 @@ - `summarise_trait_means` will trigger warning due to uninformed calculations - Added new function `extract_data` - Added new function `bind_databases` -- Added new function `flatten_databases` \ No newline at end of file +- Added new function `flatten_databases` +- Updated print function `print.traits.build` \ No newline at end of file diff --git a/R/check_compatibility.R b/R/check_compatibility.R index f2eadcb..8c0cde3 100644 --- a/R/check_compatibility.R +++ b/R/check_compatibility.R @@ -29,10 +29,7 @@ check_compatibility <- function(database, single_table_allowed = FALSE) { } 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")) + get_compiled_by_traits.build(database) if(is.null(compiled_by_traits.build) | nrow(compiled_by_traits.build) > 0) { compatible <- TRUE @@ -67,4 +64,18 @@ check_traits_compatibility <- function(trait_data){ compatible <- FALSE invisible(compatible) +} + + +#' Retrieve compiled by information from metadata table +#' +#' @param database traits.build database +#' +#' @return logical, TRUE indicating version traits table came from traits.build version > 1.0 + +get_compiled_by_traits.build <- function(database){ + database$metadata$related_identifiers %>% + convert_list_to_df2() %>% + dplyr::filter(relation_type == "isCompiledBy") %>% + dplyr::filter(stringr::str_detect(identifier, "github.com/traitecoevo/traits.build")) } \ No newline at end of file diff --git a/R/print.austraits.R b/R/print.traits.build.R similarity index 95% rename from R/print.austraits.R rename to R/print.traits.build.R index 11030e6..cc6d49f 100644 --- a/R/print.austraits.R +++ b/R/print.traits.build.R @@ -8,21 +8,30 @@ #' @export print.traits.build <- function(x, ...){ - # browser() - # Setting up + + # Setting up printing information version <- x$build_info$version %>% as.character() nrecords <- nrow(x$traits) nspecies <- unique(x$traits$taxon_name) %>% length() ntraits <- unique(x$traits$trait_name) %>% length() - if(package_version(version) < '5.0.0'){ + if(check_compatibility(x)){ + database_name <- x$metadata$title - # Setting up - database_name <- x$definitions$austraits$description - - fun <- function() { - cli::cli_h1("This database contains a total of {nrecords} records, for {nspecies} taxa and {ntraits} traits.") + traits.build_version <- x$metadata$related_identifiers |> + convert_list_to_df2() |> + dplyr::filter(resource_type == "software") |> + dplyr::pull(version) + + nice_summary_output <- function() { + cli::cli_h1("This is {version} of {database_name}!") + + cli::cli_bullets(c( + "i" = "This database is built using traits.build version {traits.build_version}", + "i" = "This database contains a total of {nrecords} records, for {nspecies} taxa and {ntraits} traits." + ) + ) cli::cli_h2("This object is a 'list' with the following components:") cli::cli_div(theme = list(span.emph = list(color = "forestgreen"))) @@ -34,32 +43,24 @@ print.traits.build <- function(x, ...){ cli::cli_li("{.emph excluded_data}: A table of data that did not pass quality test and so were excluded from the master dataset.") cli::cli_li("{.emph taxonomic_updates}: A table of all taxonomic changes implemented in the construction of AusTraits. Changes are determined by comapring against the APC (Australian Plant Census) and APNI (Australian Plant Names Index).") cli::cli_li("{.emph taxa}: A table containing details on taxa associated with information in `traits`. This information has been sourced from the APC (Australian Plant Census) and APNI (Australian Plant Names Index) and is released under a CC-BY3 license.") - cli::cli_li("{.emph definitions}: A copy of the definitions for all tables and terms. Information included here was used to process data and generate any documentation for the study.") cli::cli_li("{.emph contributors}: A table of people contributing to each study.") cli::cli_li("{.emph sources}: Bibtex entries for all primary and secondary sources in the compilation.") - cli::cli_li("{.emph build_info}: A description of the computing environment used to create this version of the dataset, including version number, git commit and R session_info.") + cli::cli_li("{.emph definitions}: A copy of the definitions for all tables and terms. Information included here was used to process data and generate any documentation for the study.") + cli::cli_li("{.emph schema}: A copy of the schema for all tables and terms. Information included here was used to process data and generate any documentation for the study.") + cli::cli_li("{.emph metadata}: Metadata associated with the dataset, including title, creators, license, subject, funding sources.") + cli::cli_li("{.emph build_info}: A description of the computing environment used to create this version of the dataset, including version number, git commit and R session_info.") cli::cli_end() cli::cli_alert_info("To access a component, try using the $ e.g. austraits$traits") } - fun() - } else{ - database_name <- x$metadata$title - - traits.build_version <- x$metadata$related_identifiers |> - convert_list_to_df2() |> - dplyr::filter(resource_type == "software") |> - dplyr::pull(version) + nice_summary_output() + } else { # If not compatible (i.e. old version of database) + # Setting up + database_name <- x$definitions$austraits$description - fun <- function() { - cli::cli_h1("This is {version} of {database_name}!") - - cli::cli_bullets(c( - "i" = "This database is built using traits.build version {traits.build_version}", - "i" = "This database contains a total of {nrecords} records, for {nspecies} taxa and {ntraits} traits." - ) - ) + old_version_nice_output <- function() { + cli::cli_h1("This database contains a total of {nrecords} records, for {nspecies} taxa and {ntraits} traits.") cli::cli_h2("This object is a 'list' with the following components:") cli::cli_div(theme = list(span.emph = list(color = "forestgreen"))) @@ -71,18 +72,16 @@ print.traits.build <- function(x, ...){ cli::cli_li("{.emph excluded_data}: A table of data that did not pass quality test and so were excluded from the master dataset.") cli::cli_li("{.emph taxonomic_updates}: A table of all taxonomic changes implemented in the construction of AusTraits. Changes are determined by comapring against the APC (Australian Plant Census) and APNI (Australian Plant Names Index).") cli::cli_li("{.emph taxa}: A table containing details on taxa associated with information in `traits`. This information has been sourced from the APC (Australian Plant Census) and APNI (Australian Plant Names Index) and is released under a CC-BY3 license.") + cli::cli_li("{.emph definitions}: A copy of the definitions for all tables and terms. Information included here was used to process data and generate any documentation for the study.") cli::cli_li("{.emph contributors}: A table of people contributing to each study.") cli::cli_li("{.emph sources}: Bibtex entries for all primary and secondary sources in the compilation.") - cli::cli_li("{.emph definitions}: A copy of the definitions for all tables and terms. Information included here was used to process data and generate any documentation for the study.") - cli::cli_li("{.emph schema}: A copy of the schema for all tables and terms. Information included here was used to process data and generate any documentation for the study.") - cli::cli_li("{.emph metadata}: Metadata associated with the dataset, including title, creators, license, subject, funding sources.") - cli::cli_li("{.emph build_info}: A description of the computing environment used to create this version of the dataset, including version number, git commit and R session_info.") + cli::cli_li("{.emph build_info}: A description of the computing environment used to create this version of the dataset, including version number, git commit and R session_info.") cli::cli_end() cli::cli_alert_info("To access a component, try using the $ e.g. austraits$traits") } - fun() + old_version_nice_output() } } diff --git a/man/get_compiled_by_traits.build.Rd b/man/get_compiled_by_traits.build.Rd new file mode 100644 index 0000000..6e48555 --- /dev/null +++ b/man/get_compiled_by_traits.build.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check_compatibility.R +\name{get_compiled_by_traits.build} +\alias{get_compiled_by_traits.build} +\title{Retrieve compiled by information from metadata table} +\usage{ +get_compiled_by_traits.build(database) +} +\arguments{ +\item{database}{traits.build database} +} +\value{ +logical, TRUE indicating version traits table came from traits.build version > 1.0 +} +\description{ +Retrieve compiled by information from metadata table +} diff --git a/man/print.traits.build.Rd b/man/print.traits.build.Rd index bf16dc7..0f31be8 100644 --- a/man/print.traits.build.Rd +++ b/man/print.traits.build.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/print.austraits.R +% Please edit documentation in R/print.traits.build.R \name{print.traits.build} \alias{print.traits.build} \title{Generic for outputting a nice summary for austraits objects}