Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/quarto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
with:
extra-packages: |
local::.
any::DT
any::dplyr
any::ggplot2
any::knitr
Expand Down
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ authors:
family-names: BV
email: www.divinehome12@gmail.com
affiliation: CMR Institute of Technology, Bengaluru
- given-names: Gaurav
family-names: Chaudhary
email: chaudharygaurav2004@gmail.com
preferred-citation:
type: article
title: >-
Expand Down
12 changes: 10 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ Title: Public Data from the BETYdb Database
Version: 0.1.0
Authors@R: c(
person("David", "LeBauer", email = "dlebauer@arizona.edu", role = c("aut", "cre")),
person("Akash B V", email = "www.divinehome12@gmail.com", role = "aut")
person("Akash B V", email = "www.divinehome12@gmail.com", role = "aut"),
person(
"Gaurav",
"Chaudhary",
email = "chaudharygaurav2004@gmail.com",
role = "ctb"
)
)
Description: An R data package providing offline access to public data from
the BETYdb database (betydb.org). Includes plant traits, crop yields,
Expand All @@ -17,14 +23,16 @@ BugReports: https://github.com/PecanProject/betydata/issues
Depends:
R (>= 4.1.0)
Suggests:
DT,
dplyr (>= 1.1.0),
ggplot2,
jsonlite,
knitr,
maps,
quarto,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
tibble
VignetteBuilder: quarto
SystemRequirements: Quarto command line tool (https://github.com/quarto-dev/quarto-cli)
Encoding: UTF-8
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# betydata (development version)

* Improved the website homepage with observation-backed summary metrics, a searchable observation preview, and summaries of the most represented
variables and species (#26).
* Replaced `Infinity` and `-Infinity` variable-bound placeholders with `NA`.


# betydata 0.1.0

## Initial Release
Expand Down
101 changes: 101 additions & 0 deletions R/homepage-data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Homepage summary helpers used by the Quarto site.

homepage_non_blank <- function(x) {
!is.na(x) & (!is.character(x) | nzchar(trimws(x)))
}

homepage_labels <- function(x) {
values <- trimws(as.character(x))
sort(unique(values[homepage_non_blank(values)]))
}

homepage_collapse_labels <- function(x) {
values <- homepage_labels(x)

if (length(values) == 0L) {
return(NA_character_)
}

paste(values, collapse = "; ")
}

homepage_metrics <- function(data) {
tibble::tibble(
metric = c(
"Observations",
"Measured variables",
"Represented species",
"Contributing sites",
"Data sources"
),
value = c(
nrow(data),
length(unique(data$trait[homepage_non_blank(data$trait)])),
length(unique(data$species_id[!is.na(data$species_id)])),
length(unique(data$site_id[!is.na(data$site_id)])),
length(unique(data$citation_id[!is.na(data$citation_id)]))
),
definition = c(
"Trait and yield records in the primary dataset",
"Distinct variables with recorded observations",
"Distinct species linked to observation records",
"Distinct research sites linked to observation records",
"Distinct cited sources linked to observation records"
)
)
}

homepage_top_traits <- function(data, n = 10L) {
data <- dplyr::filter(data, homepage_non_blank(data[["trait"]]))

summary <- dplyr::summarise(
data,
description = homepage_collapse_labels(
dplyr::pick("trait_description")[[1L]]
),
observations = dplyr::n(),
.by = "trait"
)

summary <- dplyr::arrange(
summary,
dplyr::desc(summary[["observations"]]),
summary[["trait"]]
)

dplyr::slice_head(summary, n = n)
}

homepage_top_species <- function(data, n = 10L) {
data <- dplyr::filter(data, !is.na(data[["species_id"]]))

summary <- dplyr::summarise(
data,
scientific_name = {
names <- homepage_labels(dplyr::pick("scientificname")[[1L]])

if (length(names) > 1L) {
stop(
"Each species_id must have at most one non-blank scientific name.",
call. = FALSE
)
}

if (length(names) == 0L) NA_character_ else names
},
common_name = homepage_collapse_labels(
dplyr::pick("commonname")[[1L]]
),
observations = dplyr::n(),
.by = "species_id"
)

summary <- dplyr::arrange(
summary,
dplyr::desc(summary[["observations"]]),
summary[["scientific_name"]],
summary[["species_id"]]
)

dplyr::slice_head(summary, n = n)
}
1 change: 1 addition & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ website:
format:
html:
theme: cosmo
css: inst/styles/homepage.css
toc: true
self-contained: false
df-print: paged
Expand Down
104 changes: 70 additions & 34 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,36 @@ subtitle: "Public Data from the BETYdb Database"
```{r}
#| echo: false
library(betydata)
library(dplyr)
source("R/homepage-data.R", local = TRUE)
```

**betydata** is an R data package providing offline access to public data from [BETYdb](https://betydb.org) (Biofuel Ecophysiological Traits and Yields database). It enables reproducible analyses of plant traits, crop yields, and supporting metadata without requiring database connectivity.

## Guides

| Guide | Description |
|-------|-------------|
| [Getting Started](vignettes/getting_started.qmd) | Package overview, data model, and key concepts |
| [Common Analyses](vignettes/common_analyses.qmd) | Practical analysis patterns with dplyr |
| [PFTs & Priors](vignettes/pfts-priors.qmd) | Plant Functional Types and Bayesian prior distributions |
| [Manuscript Reproduction](vignettes/manuscript.qmd) | Reproduce key analyses from LeBauer et al. (2018) |

## At a Glance

```{r}
#| echo: false
#| label: tbl-overview
#| tbl-cap: "Dataset summary"
tibble::tibble(
Metric = c(
"Total observations", "Unique traits", "Plant species",
"Research sites", "Literature citations", "Tables"
),
Value = c(
format(nrow(traitsview), big.mark = ","),
n_distinct(traitsview$trait),
format(nrow(species), big.mark = ","),
nrow(sites),
nrow(citations),
16
)
) |> knitr::kable()
#| results: asis
metrics <- homepage_metrics(traitsview)

cat("::: {.homepage-metrics}\n")
for (i in seq_len(nrow(metrics))) {
cat("::: {.homepage-metric-card}\n")
cat(sprintf("### %s\n\n", metrics$metric[[i]]))
cat(sprintf("<span class=\"homepage-metric-value\">%s</span>\n\n", format(metrics$value[[i]], big.mark = ",")))
cat(sprintf("%s\n", metrics$definition[[i]]))
cat(":::\n")
}
cat(":::\n")
```

## Installation
Expand All @@ -43,27 +48,58 @@ remotes::install_github("PecanProject/betydata")
## Quick Start

```{r}
library(betydata)
library(dplyr)
#| echo: false
if (!requireNamespace("DT", quietly = TRUE)) {
stop("Package 'DT' is required to render the searchable homepage preview.", call. = FALSE)
}

preview <- traitsview[, c(
"trait", "mean", "units", "scientificname", "sitename",
"author", "citation_year", "year"
)]
names(preview) <- c(
"Trait", "Value", "Units", "Species", "Site",
"Data-source author", "Citation year", "Observation year"
)

DT::datatable(
preview,
caption = "Searchable preview of trait and yield observations",
rownames = FALSE,
options = list(
deferRender = TRUE,
pageLength = 25,
lengthMenu = c(10, 25, 50, 100),
scrollX = TRUE
)
)
```

# The primary table -- key columns first, IDs last
traitsview
## Most Represented Variables and Species

# Bioenergy crop observations
bioenergy_genera <- c("Miscanthus", "Panicum", "Populus", "Salix", "Saccharum")
traitsview |>
filter(genus %in% bioenergy_genera) |>
count(genus, sort = TRUE)
```{r}
#| echo: false
#| label: tbl-top-traits
#| tbl-cap: "Variables with the most observation records"
homepage_top_traits(traitsview) |>
knitr::kable(
col.names = c("Variable", "Description", "Observations"),
row.names = FALSE
)
```

## Guides

| Guide | Description |
|-------|-------------|
| [Getting Started](vignettes/getting_started.qmd) | Package overview, data model, and key concepts |
| [Common Analyses](vignettes/common_analyses.qmd) | Practical analysis patterns with dplyr |
| [PFTs & Priors](vignettes/pfts-priors.qmd) | Plant Functional Types and Bayesian prior distributions |
| [Manuscript Reproduction](vignettes/manuscript.qmd) | Reproduce key analyses from LeBauer et al. (2018) |
```{r}
#| echo: false
#| label: tbl-top-species
#| tbl-cap: "Species with the most observation records"
homepage_top_species(traitsview)[
, c("scientific_name", "common_name", "observations")
] |>
knitr::kable(
col.names = c("Scientific name", "Common name", "Observations"),
row.names = FALSE
)
```

## Data License

Expand Down
29 changes: 29 additions & 0 deletions inst/styles/homepage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.homepage-metrics {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
margin: 1.5rem 0 2rem;
}

.homepage-metric-card {
border: 1px solid var(--bs-border-color, #dee2e6);
border-radius: 0.375rem;
padding: 1rem;
}

.homepage-metric-card h3 {
font-size: 1rem;
margin: 0;
}

.homepage-metric-value {
display: block;
font-size: 2rem;
font-weight: 700;
line-height: 1.2;
margin: 0.5rem 0;
}

.homepage-metric-card p {
margin: 0;
}
Loading
Loading