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

Minor fixes to print.traits.build #127

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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

Check warning on line 20 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L19-L20

Added lines #L19 - L20 were not covered by tests

# 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)

Check warning on line 25 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L22-L25

Added lines #L22 - L25 were not covered by tests

nice_summary_output <- function() {
cli::cli_h1("This is {version} of {database_name}!")

Check warning on line 28 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L27-L28

Added lines #L27 - L28 were not covered by tests

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."

Check warning on line 32 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L30-L32

Added lines #L30 - L32 were not covered by tests
)
)

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 @@
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.")

Check warning on line 51 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L48-L51

Added lines #L48 - L51 were not covered by tests
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()

Check warning on line 57 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L57

Added line #L57 was not covered by tests
} else { # If not compatible (i.e. old version of database)
# Setting up
database_name <- x$definitions$austraits$description

Check warning on line 60 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L60

Added line #L60 was not covered by tests

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

Check warning on line 63 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L62-L63

Added lines #L62 - L63 were not covered by tests

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 @@
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.")

Check warning on line 75 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L75

Added line #L75 was not covered by tests
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.")

Check warning on line 78 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L78

Added line #L78 was not covered by tests
cli::cli_end()

cli::cli_alert_info("To access a component, try using the $ e.g. austraits$traits")
}

fun()
old_version_nice_output()

Check warning on line 84 in R/print.traits.build.R

View check run for this annotation

Codecov / codecov/patch

R/print.traits.build.R#L84

Added line #L84 was not covered by tests
}
}

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.

Loading