Skip to content

Commit

Permalink
Minor fixes to print.traits.build (#127)
Browse files Browse the repository at this point in the history
* Renamed file and integrated check compatability in print funciton
  • Loading branch information
fontikar authored Nov 15, 2024
1 parent 9e11eb3 commit 1ca432f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
- Added new function `flatten_databases`
- Updated print function `print.traits.build`
19 changes: 15 additions & 4 deletions R/check_compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
}
61 changes: 30 additions & 31 deletions R/print.austraits.R → R/print.traits.build.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand All @@ -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")))
Expand All @@ -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()
}
}

Expand Down
17 changes: 17 additions & 0 deletions man/get_compiled_by_traits.build.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/print.traits.build.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ca432f

Please sign in to comment.