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

Upgrades to austraits for v.5.0.0 #85

Merged
merged 30 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
64db845
Trying out map for tests
fontikar Jan 12, 2023
7704303
Added version number to austraits_list_post
fontikar Jan 12, 2023
5e2e6a2
Added Wright_2019 in old rel test dataset so tests are consistent
fontikar Jan 12, 2023
426fc4d
Updated code to subset 4.0.0 from zenodo
fontikar Jan 12, 2023
b677567
Version testing for extract, and summarise_austriats
fontikar Jan 12, 2023
c2008c5
Combined extract_ tests and added version testing
fontikar Jan 12, 2023
5e47cfb
Version tests for join_
fontikar Jan 13, 2023
c0781b5
Version tests for widetable and renamed test files
fontikar Jan 13, 2023
50154e1
#60 fixed imports for pivot_wider, organised tests, currently not wor…
fontikar Jan 13, 2023
247db43
Minor naming adjustments in test
fontikar Jan 13, 2023
2b79ab5
Merge branch 'multi_tests' into develop: All possible tests is run th…
fontikar Jan 13, 2023
82a0f0f
Change some dependencies to imports
dfalster Jan 25, 2023
6e0cb08
Remove helper functions to vignettes
dfalster Jan 25, 2023
8f79aa6
Update deprecated functions
dfalster Jan 25, 2023
30d95cc
Restructure tests to run faster
dfalster Jan 25, 2023
9615ed0
Change GH actions triggers
dfalster Jan 25, 2023
87bdb95
ensure consistent ordering of rows
dfalster Jan 25, 2023
846ba84
Merge branch 'master' into develop
fontikar Oct 16, 2023
3564de0
bumped version number
fontikar Oct 16, 2023
4a534bf
Update to work with latest zenodo API (#81)
dfalster Oct 16, 2023
17de18c
Pulled files we want to develop from change-v5
fontikar Oct 19, 2023
f9c1666
Changes for v5 austraits.build (#78)
fontikar Nov 21, 2023
10791de
Bumped version number and updated news
fontikar Nov 21, 2023
32e5262
Added references to packages
fontikar Nov 21, 2023
a64a360
Updated version for GH steps
fontikar Nov 21, 2023
23a2f7a
Updated v number for GHA
fontikar Nov 21, 2023
147030b
Expanding testing suite to all 3 major versions of AusTraits (#86)
fontikar Nov 22, 2023
2bd66f1
Added codecov yml
fontikar Nov 22, 2023
cc8e8cf
Merge branch 'develop' of https://github.com/traitecoevo/austraits in…
fontikar Nov 22, 2023
d1c6f61
Setting limit for patch cov
fontikar Nov 22, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- master
- develop
- upgrade
pull_request:
branches:
- master
- develop

name: R-CMD-check

Expand Down
22 changes: 11 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: austraits
Title: Helpful functions to access, summarise and wrangle austraits data
Version: 2.1.2
Version: 2.2.2
Authors@R:
c(person(given = "Daniel",
family = "Falster",
Expand All @@ -22,7 +22,7 @@ Encoding: UTF-8
Language: en
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Depends:
R (>= 4.0.0),
RefManageR
Expand All @@ -39,20 +39,20 @@ Imports:
utils,
magrittr,
janitor,
lifecycle
Suggests:
lifecycle,
ggplot2,
knitr,
rmarkdown,
testthat (>= 3.0.0),
markdown,
ggpointdensity,
ggbeeswarm,
ggpointdensity,
ggbeeswarm (>= 0.7.1),
gridExtra,
scales,
forcats,
viridis,
kableExtra
lubridate
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
markdown
VignetteBuilder: knitr
Config/testthat/edition: 3
URL: https://traitecoevo.github.io/austraits/
Expand Down
5 changes: 1 addition & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ export(join_locations)
export(join_methods)
export(join_sites)
export(join_taxonomy)
export(list1_to_df)
export(load_austraits)
export(lookup_trait)
export(my_kable_styling_html)
export(my_kable_styling_markdown)
export(my_kable_styling_pdf)
export(plot_locations)
export(plot_site_locations)
export(plot_trait_distribution_beeswarm)
Expand All @@ -34,6 +30,7 @@ importFrom(dplyr,arrange)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(stats,family)
Expand Down
11 changes: 5 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# austraits 2.1.2
- Minor bug fix in `as_wide_table`
- Minor bug fix in `join_contexts`
- Removed pkgdown docs/


# austraits 2.2.2
- Upgrades to `as_wide_table`, `join_`, `trait_pivot_` to work with multiple versions of AusTraits
- Minor fixes across all function so `tidyselect` is happy
- Minor changes to documentation
- Minor fixes to `load_austraits` and `get_versions` due to Zenodo changes
163 changes: 121 additions & 42 deletions R/as_wide_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
version <- what_version(austraits)

switch (version,
'new' = as_wide_table2(austraits),
'old' = as_wide_table1(austraits),
)
"5-series" = as_wide_table3(austraits),
"4-series" = as_wide_table2(austraits),

Check warning on line 23 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L23

Added line #L23 was not covered by tests
"3-series-earlier" = as_wide_table1(austraits)
)
}

#' Turning entire AusTraits object into wide table >3.0.2
#' Turning entire AusTraits object into wide table v5
#' @noRd
#' @keywords internal
as_wide_table2 <- function(austraits){
as_wide_table3 <- function(austraits){

# Function to collapse columns in locations and contexts into single column
process_table2 <- function(data) {
process_table3 <- function(data) {
data %>%
tidyr::pivot_wider(names_from = property, values_from = value) %>%
tidyr::pivot_wider(names_from = "property", values_from = "value") %>%
tidyr::nest(data=-dplyr::any_of(c("dataset_id", "location_id", "latitude (deg)", "longitude (deg)"))) %>%
dplyr::mutate(location = purrr::map_chr(data, collapse_cols)) %>%
dplyr::select(-data)
Expand All @@ -48,61 +49,139 @@
# Getting rid of the columns that will soon be deleted in the next austraits release and renaming the description column
austraits$methods <-
austraits$methods %>%
dplyr::rename(c("dataset_description" = "description")) %>%
dplyr::rename(dataset_description = "description") %>%
dplyr::distinct()

# collapse into one column
austraits$locations <-
austraits$locations %>%
dplyr::filter(value!="unknown") %>%
dplyr::rename(c("property" = "location_property")) %>%
dplyr::rename("property" = "location_property") %>%
split(., .$dataset_id) %>%
purrr::map_dfr(process_table2)
purrr::map_dfr(process_table3)

# rename taxonomic_reference field to reflect the APC/APNI name matching process better
# rename taxonomic_dataset field to reflect the APC/APNI name matching process better
austraits$taxa <-
austraits$taxa %>%
dplyr::rename(c("taxonNameValidation" = "taxonomic_reference")) %>%
# dplyr::rename("taxonNameValidation" = "taxonomic_dataset") %>%
dplyr::distinct()

austraits_wide <-
austraits$traits %>%
dplyr::left_join(by=c("dataset_id", "location_id"), austraits$locations) %>%
dplyr::left_join(by=c("dataset_id", "trait_name"), austraits$methods) %>%
dplyr::left_join(by=c("dataset_id", "method_id", "trait_name"), austraits$methods) %>%
dplyr::left_join(by=c("taxon_name"), austraits$taxa)

# reorder the names to be more intuitive
austraits_wide %>% dplyr::select(

# The most useful (if you are filtering for just one taxon_name)
dataset_id, observation_id, trait_name, taxon_name, value, unit,
entity_type, population_id, individual_id,
value_type, basis_of_value,
replicates,
"dataset_id", "observation_id", "trait_name", "taxon_name", "value", "unit",
"entity_type", "population_id", "individual_id",
"value_type", "basis_of_value",
"replicates",
fontikar marked this conversation as resolved.
Show resolved Hide resolved
# tissue, trait_category, # Add after new zenodo release

# More stuff you can filter on
collection_date, basis_of_record, life_stage, sampling_strategy,
treatment_id, temporal_id,
"collection_date", "basis_of_record", "life_stage", "sampling_strategy",
"treatment_context_id", "temporal_context_id",

#stuff relating to locations
`latitude (deg)`, `longitude (deg)`, location, plot_id,
"latitude (deg)", "longitude (deg)", "location", "plot_context_id",

#stuff relating to contexts and methods
context, methods, method_id, original_name,
"context", "methods", "method_id", "method_context_id", "original_name",

#the citations
dataset_description, source_primary_citation, source_secondary_citation,
"dataset_description", "source_primary_citation", "source_secondary_citation",

#the taxa details
taxonomic_status, taxon_distribution,
taxon_rank, genus, family, #accepted_name_usage_id,
scientific_name_authorship
"taxonomic_status", "taxon_distribution",
"taxon_rank", "genus", "family"
)

austraits_wide
}

#' Turning entire AusTraits object into wide table v4
#' @noRd
#' @keywords internal
as_wide_table2 <- function(austraits){

# Function to collapse columns in locations and contexts into single column
process_table2 <- function(data) {
data %>%
tidyr::pivot_wider(names_from = "property", values_from = "value") %>%
tidyr::nest(data=-dplyr::any_of(c("dataset_id", "location_id", "latitude (deg)", "longitude (deg)"))) %>%
dplyr::mutate(location = purrr::map_chr(data, collapse_cols)) %>%
dplyr::select(-data)

Check warning on line 117 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L112-L117

Added lines #L112 - L117 were not covered by tests
}

################################################################################
# Define and adapt each table in the list of austraits to prepare for the wide table format

# The contexts table needs the contexts collapsed to one context name per site
austraits %>%
join_contexts(collapse_context = TRUE) -> austraits

Check warning on line 125 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L124-L125

Added lines #L124 - L125 were not covered by tests

# Getting rid of the columns that will soon be deleted in the next austraits release and renaming the description column
austraits$methods <-
austraits$methods %>%
dplyr::rename(dataset_description = "description") %>%
dplyr::distinct()

Check warning on line 131 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L128-L131

Added lines #L128 - L131 were not covered by tests

# collapse into one column
austraits$locations <-
austraits$locations %>%
dplyr::filter(value!="unknown") %>%
dplyr::rename("property" = "location_property") %>%
split(., .$dataset_id) %>%
purrr::map_dfr(process_table2)

Check warning on line 139 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L134-L139

Added lines #L134 - L139 were not covered by tests

# rename taxonomic_dataset field to reflect the APC/APNI name matching process better
austraits$taxa <-
austraits$taxa %>%
dplyr::rename("taxonNameValidation" = "taxonomic_dataset") %>%
dplyr::distinct()

Check warning on line 145 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L142-L145

Added lines #L142 - L145 were not covered by tests

austraits_wide <-
austraits$traits %>%
dplyr::left_join(by=c("dataset_id", "location_id"), austraits$locations) %>%
dplyr::left_join(by=c("dataset_id", "trait_name"), austraits$methods) %>%
dplyr::left_join(by=c("taxon_name"), austraits$taxa)

Check warning on line 151 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L147-L151

Added lines #L147 - L151 were not covered by tests

# reorder the names to be more intuitive
austraits_wide %>% dplyr::select(dplyr::any_of(

Check warning on line 154 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L154

Added line #L154 was not covered by tests

# The most useful (if you are filtering for just one taxon_name)
"dataset_id", "observation_id", "trait_name", "taxon_name", "value", "unit",
"entity_type", "population_id", "individual_id",
"value_type", "basis_of_value",
"replicates",

Check warning on line 160 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L157-L160

Added lines #L157 - L160 were not covered by tests
# tissue, trait_category, # Add after new zenodo release

# More stuff you can filter on
"collection_date", "basis_of_record", "life_stage", "sampling_strategy",
"treatment_id", "temporal_id",

Check warning on line 165 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L164-L165

Added lines #L164 - L165 were not covered by tests

#stuff relating to locations
"latitude (deg)", "longitude (deg)", "location", "plot_id",

Check warning on line 168 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L168

Added line #L168 was not covered by tests

#stuff relating to contexts and methods
"context", "methods", "method_id", "original_name",

Check warning on line 171 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L171

Added line #L171 was not covered by tests

#the citations
"dataset_description", "source_primary_citation", "source_secondary_citation",

Check warning on line 174 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L174

Added line #L174 was not covered by tests

#the taxa details
"taxonomic_status", "taxon_distribution",
"taxon_rank", "genus", "family"

Check warning on line 178 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L177-L178

Added lines #L177 - L178 were not covered by tests

))

austraits_wide

Check warning on line 182 in R/as_wide_table.R

View check run for this annotation

Codecov / codecov/patch

R/as_wide_table.R#L182

Added line #L182 was not covered by tests
}

#' Turning entire AusTraits object into wide table <=3.0.2
#' @noRd
#' @keywords internal
Expand All @@ -128,7 +207,7 @@
process_table <- function(data) {

data %>%
tidyr::pivot_wider(names_from = property, values_from = value) %>%
tidyr::pivot_wider(names_from = "property", values_from = "value") %>%
tidyr::nest(data=-dplyr::any_of(c("dataset_id", "site_name", "context_name", "latitude (deg)", "longitude (deg)"))) %>%
dplyr::mutate(site = purrr::map_chr(data, collapse_cols)) %>%
dplyr::select(-data)
Expand All @@ -140,15 +219,15 @@
# the trait table needs little prep. Rename the value columns as value
austraits$traits <-
austraits$traits %>%
dplyr::rename(c("trait_value" = "value"))
dplyr::rename(trait_value = "value")

# The contexts table needs the contexts collapsed to one context name per site
austraits$contexts <-
austraits$contexts %>%
dplyr::rename(c("property" = "context_property")) %>%
dplyr::rename(property = "context_property") %>%
split(austraits$contexts$dataset_id) %>%
purrr::map_dfr(process_table) %>%
dplyr::rename(c("context" = "site"))
dplyr::rename(context = "site")

# Getting rid of the columns that will soon be deleted in the next austraits release and renaming the description column
austraits$methods <-
Expand All @@ -161,23 +240,23 @@
dplyr::slice(1) %>%
dplyr:: ungroup() %>%
#------------
dplyr::select(-year_collected_start, -year_collected_end) %>%
dplyr::rename(c("dataset_description" = "description"))
dplyr::select(-c("year_collected_start", "year_collected_end")) %>%
dplyr::rename(dataset_description = "description")

# collapse into one column
austraits$sites <-
austraits$sites %>%
dplyr::filter(value!="unknown") %>%
# next line is a fix -- one dataset in 3.0.2 has value "site_name"
dplyr::mutate(site_property = gsub("site_name", "name", site_property)) %>%
dplyr::rename(c("property" = "site_property")) %>%
dplyr::rename("property" = "site_property") %>%
fontikar marked this conversation as resolved.
Show resolved Hide resolved
split(., .$dataset_id) %>%
purrr::map_dfr(process_table)

# rename source data field to reflect the APC/APNI name matching process better
austraits$taxa <-
austraits$taxa %>%
dplyr::rename(c("taxonNameValidation" = "source"))
dplyr::rename(taxonNameValidation = "source")

austraits_wide <-
austraits$traits %>%
Expand All @@ -190,26 +269,26 @@
dplyr::select(

# The most useful (if you are filtering for just one taxon_name)
dataset_id, observation_id, trait_name, taxon_name, trait_value, unit,
value_type, replicates,
"dataset_id", "observation_id", "trait_name", "taxon_name", "trait_value", "unit",
"value_type", "replicates",
# tissue, trait_category, # Add after new zenodo release

# More stuff you can filter on
date, collection_type, sample_age_class, sampling_strategy,
"date", "collection_type", "sample_age_class", "sampling_strategy",

#stuff relating to sites
`latitude (deg)`, `longitude (deg)`, site_name, site,
"latitude (deg)", "longitude (deg)", "site_name", "site",

#stuff relating to contexts and methods
context_name, context, methods, original_name,
"context_name", "context", "methods", "original_name",

#the citations
dataset_description, source_primary_citation, source_secondary_citation,
"dataset_description", "source_primary_citation", "source_secondary_citation",

#the taxa details
taxonomicStatus, taxonDistribution,
taxonRank, genus, family, acceptedNameUsageID,
scientificNameAuthorship, ccAttributionIRI
"taxonomicStatus", "taxonDistribution",
"taxonRank", "genus", "family", "acceptedNameUsageID",
"scientificNameAuthorship", "ccAttributionIRI"
)

austraits_wide
Expand Down
Loading
Loading