-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- traits.build paper published in Sep 2024 in Ecological Informatics (DOI: 10.1016/j.ecoinf.2024.102773) - Minor updates to ontology, which is now version 1.0.0 - Added standard error and standard deviation as value types Moved functions to austraits package and made austraits package a dependancy Renamed some of the functions that are now moved to austraits package bind_databases <-- build_combine convert_df_to_list <-- util_df_to_list convert_list_to_df1 <-- util_list_to_df1 convert_list_to_df2 <-- util_list_to_df2 Renamed functions still also assigned their old name, with a deprecation warning indicating the new name plot_trait_distribution_beeswarm, trait_pivot_longer and trait_pivot_wider had been in both austraits and traits.build packages and have now been removed from traits.build Import new austraits function flatten_database (had been suggested to be database_create_combined_table) Refactoring of test functions used by dataset_test Added tests using the dataset_test function, so it is checked explicitly by traits.build (run on Example datasets) Minor bug fixes Issues addressed since last traits.build release: Issue #150 & Issue #154 (error if no contexts) Issue #179 (incorrect test written that flagged an error if input/output units identical) Issue #171 (SE required as a value type) Issue #131 (remove duplicate functions) Issue #183 (deprecated function still being used) Issue #185 (context table columns mis-ordered, dataset test failing) Issue #143 (add dataset_test tests) --------- Co-authored-by: Daniel Falster <[email protected]> Co-authored-by: Fonti Kar <[email protected]> Co-authored-by: Sophie Yang <[email protected]>
- Loading branch information
1 parent
a09dea8
commit e15d2a1
Showing
224 changed files
with
68,012 additions
and
2,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: traits.build | ||
Title: A workflow for harmonising trait data from diverse sources into a documented standard structure | ||
Version: 1.1.0 | ||
Version: 2.0.0 | ||
Maintainer: Daniel Falster <[email protected]> | ||
Authors@R: c( | ||
person(given = "Daniel", family = "Falster", role = c("cre", "aut"), email = "[email protected]", comment = c(ORCID = "0000-0002-9814-092X")), | ||
|
@@ -22,7 +22,8 @@ Depends: | |
lubridate, | ||
readr, | ||
stringr, | ||
tidyr | ||
tidyr, | ||
austraits | ||
Imports: | ||
crayon, | ||
git2r, | ||
|
@@ -38,7 +39,8 @@ Imports: | |
testthat, | ||
tibble, | ||
whisker, | ||
yaml | ||
yaml, | ||
lifecycle | ||
Suggests: | ||
furrr, | ||
remake, | ||
|
@@ -57,8 +59,10 @@ Suggests: | |
zip, | ||
covr | ||
Remotes: | ||
richfitz/remake | ||
richfitz/remake, | ||
traitecoevo/austraits | ||
Encoding: UTF-8 | ||
VignetteBuilder: knitr | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.2 | ||
Config/testthat/edition: 3 | ||
Roxygen: list(markdown = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,108 +30,3 @@ check_pivot_wider <- function(dataset) { | |
} | ||
|
||
} | ||
|
||
|
||
#' @title Pivot long format data into a wide format | ||
#' | ||
#' @description `trait_pivot_wider` "widens" long format data ("tidy data"). | ||
#' | ||
#' Databases built with `traits.build` are organised in a long format where observations are on different rows and the | ||
#' type of observation is denoted by various identifying columns (e.g `trait_name`, `dataset_id`, | ||
#' `observation_id`, etc.). | ||
#' This function converts the data into wide format so that each trait in its own column. | ||
#' | ||
#' @param traits The traits table from database (list object) | ||
#' @return A tibble in wide format | ||
#' @details `trait_pivot_wider` will return a single wide tibble; note that some meta-data columns | ||
#' (unit, replicates, measurement_remarks, basis_of_record, basis_of_value) will be excluded to | ||
#' produce a useful wide tibble. | ||
#' @examples | ||
#' \dontrun{ | ||
#' data <- austraits$traits %>% filter(dataset_id == "Falster_2003") | ||
#' data # Long format | ||
#' traits_wide <- trait_pivot_wider(data) | ||
#' traits_wide # Wide format | ||
#' } | ||
#' @author Daniel Falster - [email protected] | ||
#' @export | ||
db_traits_pivot_wider <- function(traits) { | ||
|
||
metadata_cols <- c("unit", "replicates", "measurement_remarks", "basis_of_value") | ||
|
||
# A check for if there are more than 1 value_type for a given taxon_name, observation_id and method | ||
check_value_type <- traits %>% | ||
dplyr::select(dplyr::all_of(c( | ||
"trait_name", "value", "dataset_id", "observation_id", "method_id", "method_context_id", | ||
"repeat_measurements_id", "value_type"))) %>% | ||
dplyr::group_by( | ||
.data$dataset_id, .data$observation_id, .data$method_id, | ||
.data$method_context_id, .data$repeat_measurements_id) %>% | ||
dplyr::summarise(n_value_type = length(unique(.data$value_type))) %>% | ||
dplyr::arrange(.data$observation_id) %>% | ||
dplyr::filter(.data$n_value_type > 1) | ||
|
||
if (nrow(check_value_type) > 1) { | ||
|
||
traits %>% | ||
tidyr::pivot_wider( | ||
names_from = "trait_name", | ||
values_from = "value", | ||
id_cols = -dplyr::all_of(metadata_cols) | ||
) | ||
|
||
} else { | ||
|
||
metadata_cols <- c(metadata_cols, "value_type") | ||
|
||
traits %>% | ||
tidyr::pivot_wider( | ||
names_from = "trait_name", | ||
values_from = "value", | ||
id_cols = -dplyr::all_of(metadata_cols) | ||
) | ||
} | ||
|
||
} | ||
|
||
|
||
#' @title Pivot wide format data into a long format | ||
#' | ||
#' @description `trait_pivot_longer` "gathers" wide format data into a "tidy" format. | ||
#' | ||
#' This function converts the data into long format where observations are on different rows and the type of | ||
#' observation is denoted by the `trait_name` column. | ||
#' In other words, `trait_pivot_longer` reverts the actions of `trait_pivot_wider`. | ||
#' @param wide_data Output from `trait_pivot_wider` (a tibble of wide data) | ||
#' @return A tibble in long format | ||
#' @details | ||
#' `trait_pivot_longer` will return a tibble with fewer columns than the original traits table | ||
#' The excluded columns include: "unit", "replicates", "measurement_remarks", "basis_of_record", | ||
#' "basis_of_value" # Double check #TODO | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' data <- austraits$traits %>% | ||
#' filter(dataset_id == "Falster_2003") | ||
#' data # Long format | ||
#' traits_wide <- trait_pivot_wider(data) | ||
#' traits_wide # Wide format | ||
#' | ||
#' values_long <- trait_pivot_longer(traits_wide) | ||
#' } | ||
#' @author Daniel Falster - [email protected] | ||
#' @author Fonti Kar - [email protected] | ||
#' @export | ||
db_traits_pivot_longer <- function(wide_data) { | ||
|
||
# The start of the trait columns is after `original_name` | ||
start_of_trait_cols <- which(names(wide_data) == "original_name") + 1 | ||
|
||
wide_data %>% | ||
tidyr::pivot_longer( | ||
cols = start_of_trait_cols:ncol(.), | ||
names_to = "trait_name", | ||
values_drop_na = TRUE | ||
) | ||
|
||
} |
Oops, something went wrong.