From be354968d8d2a7e817ecde60d9cec615259523dc Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Fri, 5 Jun 2026 16:23:15 -0700 Subject: [PATCH 1/7] create list col of bibentries --- R/flux_citations.R | 100 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 R/flux_citations.R diff --git a/R/flux_citations.R b/R/flux_citations.R new file mode 100644 index 0000000..cfd5328 --- /dev/null +++ b/R/flux_citations.R @@ -0,0 +1,100 @@ +flux_citations <- function( + site_ids, + output = c("table", "bibtex"), + output_path = NULL, + ... +) { + list <- flux_listall(...) + site_citations_raw <- list %>% + filter(site_id %in% site_ids) %>% + select( + site_id, + site_name, + data_hub, + product_citation, + product_id, + oneflux_code_version + ) + + by_hub <- split( + site_citations_raw, + site_citations_raw$data_hub + ) + amf_pattern <- "^(.+)\\((\\d{4})\\), (.+) Ver\\. .+, (.+), \\(Dataset\\)\\. (.+)$" + amf_split <- stringr::str_match( + by_hub$AmeriFlux$product_citation, + pattern = amf_pattern + ) %>% + as_tibble() + colnames(amf_split) <- c( + "product_citation", + "authors", + "year", + "title", + "publisher", + "url" + ) + + amf <- left_join( + by_hub$AmeriFlux, + amf_split, + by = join_by(product_citation) + ) %>% + mutate(doi = product_id) + + # For ICOS, sometimes there is no author + icos_pattern <- "^(.+)?\\s?\\((\\d{4})\\)\\. (.+), FLUXNET, (https.+)$" + icos_split <- stringr::str_match( + by_hub$ICOS$product_citation, + pattern = icos_pattern + ) %>% + as_tibble() + colnames(icos_split) <- c( + "product_citation", + "authors", + "year", + "title", + "url" + ) + icos <- left_join(by_hub$ICOS, icos_split, by = join_by(product_citation)) %>% + mutate( + publisher = "Ecosystem Thematic Centre", + pid = product_id + ) + + tern_pattern <- "^(.+)\\((\\d{4})\\): (.+\\.).?Version.+" + tern_split <- stringr::str_match( + by_hub$TERN$product_citation, + pattern = tern_pattern + ) %>% + as_tibble() + colnames(tern_split) <- c("product_citation", "authors", "year", "title") + tern <- left_join(by_hub$TERN, tern_split, by = join_by(product_citation)) %>% + mutate( + publisher = "Terrestrial Ecosystem Research Network (TERN)", + url = product_id, + doi = stringr::str_remove(product_id, "https:\\/\\/dx.doi.org\\/") + ) + + bibentries <- bind_rows(amf, icos, tern) %>% + mutate(type = "dataset") %>% + select(-product_citation) %>% + nest(.by = c(site_id, site_name, product_id)) %>% + mutate( + bibentry = map(data, \(x) { + bibentry( + "misc", + author = x$authors, + title = x$title, + year = x$year, + publisher = x$publisher, + doi = x$doi, + pid = x$pid, + url = x$url, + type = "dataset" + ) + }) + ) %>% + select(-data) +} + From 436917745d189945d2cddcdb02d45898c9760362 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 8 Jun 2026 10:19:01 -0700 Subject: [PATCH 2/7] document, add tests --- NAMESPACE | 1 + R/flux_citations.R | 196 +++++++++++++++++++-------- man/flux_citations.Rd | 57 ++++++++ tests/testthat/test-flux_citations.R | 20 +++ 4 files changed, 219 insertions(+), 55 deletions(-) create mode 100644 man/flux_citations.Rd create mode 100644 tests/testthat/test-flux_citations.R diff --git a/NAMESPACE b/NAMESPACE index d51840a..aa87135 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(flux_amf_credentials) export(flux_badm) +export(flux_citations) export(flux_discover_files) export(flux_download) export(flux_extract) diff --git a/R/flux_citations.R b/R/flux_citations.R index cfd5328..24acf2a 100644 --- a/R/flux_citations.R +++ b/R/flux_citations.R @@ -1,7 +1,43 @@ +#' Output required per-dataset citations for FLUXNET data +#' +#' Given a vector of site IDs, this either returns a dataframe with or BibTeX +#' citations for each site. +#' +#' @param site_ids Character vector of site IDs, e.g. `c("AR-Bal", "DE-Gwg")`. +#' @param output Either `"data.frame"` to return a tibble or `"bibtex"` to +#' return (or write) BibTeX entries. See '**Value**' for more details. +#' @param bibtex_path Path to a .bib file to write BibTeX to, passed to the +#' `con` argument of [writeLines()]. If `NULL` (default), BibTeX will be +#' returned as character. Has no effect if `output = 'data.frame'`. +#' @param ... Additional arguments passed to [flux_listall()]. +#' +#' @returns If `output = 'data.frame'`, a `tibble` is returned with a +#' `bibentry` list-column with elements of class [bibentry] and a `citation` +#' column with citations formatted in the default style (see the `format()` +#' method for [bibentry()] for more details). If `output = 'bibtex'`, BibTeX +#' entries are either returned as an atomic character vector (if `bibtex_path` +#' is `NULL`) or written to a file. +#' @examples +#' # Return dataframe with bibentries and formatted citations +#' flux_citations(c("AR-Bal", "DE-Gwg")) +#' +#' # Return BibTeX +#' flux_citations(c("AR-Bal", "DE-Gwg"), output = "bibtex") +#' +#' # Append BibTeX entries to a file +#' \dontrun{ +#' flux_citations( +#' c("AR-Bal", "DE-Gwg"), +#' output = "bibtex", +#' bibtex_path = "references.bib" +#' ) +#' } +#' +#' @export flux_citations <- function( site_ids, - output = c("table", "bibtex"), - output_path = NULL, + output = c("data.frame", "bibtex"), + bibtex_path = NULL, ... ) { list <- flux_listall(...) @@ -20,65 +56,87 @@ flux_citations <- function( site_citations_raw, site_citations_raw$data_hub ) - amf_pattern <- "^(.+)\\((\\d{4})\\), (.+) Ver\\. .+, (.+), \\(Dataset\\)\\. (.+)$" - amf_split <- stringr::str_match( - by_hub$AmeriFlux$product_citation, - pattern = amf_pattern - ) %>% - as_tibble() - colnames(amf_split) <- c( - "product_citation", - "authors", - "year", - "title", - "publisher", - "url" - ) - - amf <- left_join( - by_hub$AmeriFlux, - amf_split, - by = join_by(product_citation) - ) %>% - mutate(doi = product_id) - # For ICOS, sometimes there is no author - icos_pattern <- "^(.+)?\\s?\\((\\d{4})\\)\\. (.+), FLUXNET, (https.+)$" - icos_split <- stringr::str_match( - by_hub$ICOS$product_citation, - pattern = icos_pattern - ) %>% - as_tibble() - colnames(icos_split) <- c( - "product_citation", - "authors", - "year", - "title", - "url" - ) - icos <- left_join(by_hub$ICOS, icos_split, by = join_by(product_citation)) %>% - mutate( - publisher = "Ecosystem Thematic Centre", - pid = product_id + if (!is.null(by_hub$AmeriFlux)) { + amf_pattern <- "^(.+)\\((\\d{4})\\), (.+), Ver\\. .+, (.+), \\(Dataset\\)\\. (.+)$" + amf_split <- stringr::str_match( + by_hub$AmeriFlux$product_citation, + pattern = amf_pattern + ) %>% + as_tibble() + colnames(amf_split) <- c( + "product_citation", + "authors", + "year", + "title", + "publisher", + "url" ) - tern_pattern <- "^(.+)\\((\\d{4})\\): (.+\\.).?Version.+" - tern_split <- stringr::str_match( - by_hub$TERN$product_citation, - pattern = tern_pattern - ) %>% - as_tibble() - colnames(tern_split) <- c("product_citation", "authors", "year", "title") - tern <- left_join(by_hub$TERN, tern_split, by = join_by(product_citation)) %>% - mutate( - publisher = "Terrestrial Ecosystem Research Network (TERN)", - url = product_id, - doi = stringr::str_remove(product_id, "https:\\/\\/dx.doi.org\\/") + amf <- left_join( + by_hub$AmeriFlux, + amf_split, + by = join_by(product_citation) + ) %>% + mutate(doi = product_id) + } else { + amf <- tibble() + } + + if (!is.null(by_hub$ICOS)) { + # For ICOS, sometimes there is no author + icos_pattern <- "^(.+)?\\s?\\((\\d{4})\\)\\. (.+), FLUXNET, (https.+)$" + icos_split <- stringr::str_match( + by_hub$ICOS$product_citation, + pattern = icos_pattern + ) %>% + as_tibble() + colnames(icos_split) <- c( + "product_citation", + "authors", + "year", + "title", + "url" ) + icos <- left_join( + by_hub$ICOS, + icos_split, + by = join_by(product_citation) + ) %>% + mutate( + publisher = "Ecosystem Thematic Centre", + pid = product_id + ) + } else { + icos <- tibble() + } - bibentries <- bind_rows(amf, icos, tern) %>% + if (!is.null(by_hub$TERN)) { + tern_pattern <- "^(.+)\\((\\d{4})\\): (.+\\.).?Version.+" + tern_split <- stringr::str_match( + by_hub$TERN$product_citation, + pattern = tern_pattern + ) %>% + as_tibble() + colnames(tern_split) <- c("product_citation", "authors", "year", "title") + tern <- left_join( + by_hub$TERN, + tern_split, + by = join_by(product_citation) + ) %>% + mutate( + publisher = "Terrestrial Ecosystem Research Network (TERN)", + url = product_id, + doi = stringr::str_remove(product_id, "https:\\/\\/dx.doi.org\\/") + ) + } else { + tern <- tibble() + } + combined <- bind_rows(amf, icos, tern) %>% mutate(type = "dataset") %>% - select(-product_citation) %>% + select(-product_citation) + + bibentries <- combined %>% nest(.by = c(site_id, site_name, product_id)) %>% mutate( bibentry = map(data, \(x) { @@ -96,5 +154,33 @@ flux_citations <- function( }) ) %>% select(-data) + + # Add cite keys + # TODO: make these Zotero/BetterBibTex style with a piece of the title in them + # to make them more likely to be unique + bibentries$bibentry <- bibentries$bibentry %>% + map(\(x) { + first_author_family <- tolower(x$author[[1]]$family) + if (is.null(first_author_family)) { + first_author_family <- "noauthor" + } + x$key <- paste(first_author_family, x$year, sep = "_") + x + }) + + output <- match.arg(output) + if (output == "data.frame") { + bibentries %>% mutate(citation = map_chr(bibentry, format)) + } else if (output == "bibtex") { + bibtex_list <- map_chr(bibentries$bibentry, \(x) { + format(x, style = "bibtex") + }) + bibtex_text <- glue::glue_collapse(bibtex_list, sep = "\n") + if (is.null(bibtex_path)) { + return(bibtex_text) + } else { + writeLines(bibtex_text, bibtex_path) + } + } } diff --git a/man/flux_citations.Rd b/man/flux_citations.Rd new file mode 100644 index 0000000..913dbc5 --- /dev/null +++ b/man/flux_citations.Rd @@ -0,0 +1,57 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flux_citations.R +\name{flux_citations} +\alias{flux_citations} +\title{Output required per-dataset citations for FLUXNET data} +\usage{ +flux_citations( + site_ids, + output = c("data.frame", "bibtex"), + output_path = NULL, + ... +) +} +\arguments{ +\item{site_ids}{Character vector of site IDs, e.g. \code{c("AR-Bal", "DE-Gwg")}.} + +\item{output}{Either \code{"data.frame"} to return a tibble or \code{"bibtex"} to +return (or write) BibTeX entries. See '\strong{Value}' for more details.} + +\item{...}{Additional arguments passed to \code{\link[=flux_listall]{flux_listall()}}.} + +\item{bibtex_path}{Path to a .bib file to write BibTeX to, passed to the +\code{con} argument of \code{\link[=writeLines]{writeLines()}}. If \code{NULL} (default), BibTeX will be +returned as character. Has no effect if \code{output = 'data.frame'}.} +} +\value{ +If \code{output = 'data.frame'}, a \code{tibble} is returned with a +\code{bibentry} list-column with elements of class \link{bibentry} and a \code{citation} +column with citations formatted in the default style (see the \code{format()} +method for \code{\link[=bibentry]{bibentry()}} for more details). If \code{output = 'bibtex'}, BibTeX +entries are either returned as an atomic character vector (if \code{bibtex_path} +is \code{NULL}) or written to a file. +} +\description{ +Given a vector of site IDs, this either returns a dataframe with or BibTeX +citations for each site. +} +\examples{ + +# Return dataframe with bibentries and formatted citations +flux_citations(c("AR-Bal", "DE-Gwg")) + +# Return BibTeX +flux_citations(c("AR-Bal", "DE-Gwg"), output = "bibtex") + +# Append BibTeX entries to a file +\dontrun{ + +flux_citations( + c("AR-Bal", "DE-Gwg"), + output = "bibtex", + bibtex_path = "references.bib" +) + +} + +} diff --git a/tests/testthat/test-flux_citations.R b/tests/testthat/test-flux_citations.R new file mode 100644 index 0000000..bdeb0e3 --- /dev/null +++ b/tests/testthat/test-flux_citations.R @@ -0,0 +1,20 @@ +test_that("citations work", { + citations <- flux_citations( + site_ids = c("AR-Bal", "DE-Gwg"), + output = "data.frame" + ) + expect_s3_class(citations, "data.frame") + expect_s3_class(citations$bibentry[[1]], "bibentry") +}) + +test_that("writing to bibtex works", { + tmp <- withr::local_tempfile(fileext = ".bib") + citations <- flux_citations( + site_ids = c("AR-Bal", "DE-Gwg"), + output = "bibtex", + bibtex_path = tmp + ) + expect_true( + readLines(tmp)[3] == " title = {AmeriFlux FLUXNET-1F AR-Bal Balcarce BA}," + ) +}) From 8633a7146f9b767882daa3eda40660056ef407a0 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 8 Jun 2026 10:43:41 -0700 Subject: [PATCH 3/7] namespace --- R/flux_citations.R | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/R/flux_citations.R b/R/flux_citations.R index 24acf2a..3119d05 100644 --- a/R/flux_citations.R +++ b/R/flux_citations.R @@ -42,8 +42,8 @@ flux_citations <- function( ) { list <- flux_listall(...) site_citations_raw <- list %>% - filter(site_id %in% site_ids) %>% - select( + dplyr::filter(site_id %in% site_ids) %>% + dplyr::select( site_id, site_name, data_hub, @@ -63,7 +63,7 @@ flux_citations <- function( by_hub$AmeriFlux$product_citation, pattern = amf_pattern ) %>% - as_tibble() + dplyr::as_tibble() colnames(amf_split) <- c( "product_citation", "authors", @@ -73,14 +73,14 @@ flux_citations <- function( "url" ) - amf <- left_join( + amf <- dplyr::left_join( by_hub$AmeriFlux, amf_split, - by = join_by(product_citation) + by = "product_citation" ) %>% - mutate(doi = product_id) + dplyr::mutate(doi = product_id) } else { - amf <- tibble() + amf <- dplyr::tibble() } if (!is.null(by_hub$ICOS)) { @@ -90,7 +90,7 @@ flux_citations <- function( by_hub$ICOS$product_citation, pattern = icos_pattern ) %>% - as_tibble() + dplyr::as_tibble() colnames(icos_split) <- c( "product_citation", "authors", @@ -98,17 +98,17 @@ flux_citations <- function( "title", "url" ) - icos <- left_join( + icos <- dplyr::left_join( by_hub$ICOS, icos_split, - by = join_by(product_citation) + by = "product_citation" ) %>% - mutate( + dplyr::mutate( publisher = "Ecosystem Thematic Centre", pid = product_id ) } else { - icos <- tibble() + icos <- dplyr::tibble() } if (!is.null(by_hub$TERN)) { @@ -117,29 +117,29 @@ flux_citations <- function( by_hub$TERN$product_citation, pattern = tern_pattern ) %>% - as_tibble() + dplyr::as_tibble() colnames(tern_split) <- c("product_citation", "authors", "year", "title") - tern <- left_join( + tern <- dplyr::left_join( by_hub$TERN, tern_split, - by = join_by(product_citation) + by = "product_citation" ) %>% - mutate( + dplyr::mutate( publisher = "Terrestrial Ecosystem Research Network (TERN)", url = product_id, doi = stringr::str_remove(product_id, "https:\\/\\/dx.doi.org\\/") ) } else { - tern <- tibble() + tern <- dplyr::tibble() } - combined <- bind_rows(amf, icos, tern) %>% - mutate(type = "dataset") %>% - select(-product_citation) + combined <- dplyr::bind_rows(amf, icos, tern) %>% + dplyr::mutate(type = "dataset") %>% + dplyr::select(-product_citation) bibentries <- combined %>% - nest(.by = c(site_id, site_name, product_id)) %>% - mutate( - bibentry = map(data, \(x) { + tidyr::nest(.by = c(site_id, site_name, product_id)) %>% + dplyr::mutate( + bibentry = purrr::map(data, \(x) { bibentry( "misc", author = x$authors, @@ -153,13 +153,13 @@ flux_citations <- function( ) }) ) %>% - select(-data) + dplyr::select(-data) # Add cite keys # TODO: make these Zotero/BetterBibTex style with a piece of the title in them # to make them more likely to be unique bibentries$bibentry <- bibentries$bibentry %>% - map(\(x) { + purrr::map(\(x) { first_author_family <- tolower(x$author[[1]]$family) if (is.null(first_author_family)) { first_author_family <- "noauthor" @@ -170,9 +170,9 @@ flux_citations <- function( output <- match.arg(output) if (output == "data.frame") { - bibentries %>% mutate(citation = map_chr(bibentry, format)) + bibentries %>% dplyr::mutate(citation = purrr::map_chr(bibentry, format)) } else if (output == "bibtex") { - bibtex_list <- map_chr(bibentries$bibentry, \(x) { + bibtex_list <- purrr::map_chr(bibentries$bibentry, \(x) { format(x, style = "bibtex") }) bibtex_text <- glue::glue_collapse(bibtex_list, sep = "\n") From 0485560a5446b9cfc3c28b6559356bfb6a20a150 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 8 Jun 2026 10:46:30 -0700 Subject: [PATCH 4/7] update news --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index a5a87c0..5d6342e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # fluxnet (development version) +* Added `flux_citations()` to generate site-level citations either as plain text or BibTex entries. * Fixed a bug where hourly data wasn't being extracted or read in along with half-hourly data ([#73](https://github.com/EcosystemEcologyLab/fluxnet-package/issues/73)) # fluxnet 0.3.2 From 0f5f1289b8719f90b0b30b832783219643cff037 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 8 Jun 2026 10:59:33 -0700 Subject: [PATCH 5/7] check notes --- R/flux_citations.R | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/R/flux_citations.R b/R/flux_citations.R index 3119d05..73dc7e7 100644 --- a/R/flux_citations.R +++ b/R/flux_citations.R @@ -42,15 +42,15 @@ flux_citations <- function( ) { list <- flux_listall(...) site_citations_raw <- list %>% - dplyr::filter(site_id %in% site_ids) %>% - dplyr::select( - site_id, - site_name, - data_hub, - product_citation, - product_id, - oneflux_code_version - ) + dplyr::filter(.data$site_id %in% site_ids) %>% + dplyr::select(dplyr::all_of(c( + "site_id", + "site_name", + "data_hub", + "product_citation", + "product_id", + "oneflux_code_version" + ))) by_hub <- split( site_citations_raw, @@ -78,7 +78,7 @@ flux_citations <- function( amf_split, by = "product_citation" ) %>% - dplyr::mutate(doi = product_id) + dplyr::mutate(doi = .data$product_id) } else { amf <- dplyr::tibble() } @@ -105,7 +105,7 @@ flux_citations <- function( ) %>% dplyr::mutate( publisher = "Ecosystem Thematic Centre", - pid = product_id + pid = .data$product_id ) } else { icos <- dplyr::tibble() @@ -126,21 +126,21 @@ flux_citations <- function( ) %>% dplyr::mutate( publisher = "Terrestrial Ecosystem Research Network (TERN)", - url = product_id, - doi = stringr::str_remove(product_id, "https:\\/\\/dx.doi.org\\/") + url = .data$product_id, + doi = stringr::str_remove(.data$product_id, "https:\\/\\/dx.doi.org\\/") ) } else { tern <- dplyr::tibble() } combined <- dplyr::bind_rows(amf, icos, tern) %>% dplyr::mutate(type = "dataset") %>% - dplyr::select(-product_citation) + dplyr::select(-dplyr::all_of("product_citation")) bibentries <- combined %>% - tidyr::nest(.by = c(site_id, site_name, product_id)) %>% + tidyr::nest(.by = c("site_id", "site_name", "product_id")) %>% dplyr::mutate( - bibentry = purrr::map(data, \(x) { - bibentry( + bibentry = purrr::map(.data$data, \(x) { + utils::bibentry( "misc", author = x$authors, title = x$title, @@ -153,7 +153,7 @@ flux_citations <- function( ) }) ) %>% - dplyr::select(-data) + dplyr::select(-dplyr::all_of("data")) # Add cite keys # TODO: make these Zotero/BetterBibTex style with a piece of the title in them @@ -170,7 +170,7 @@ flux_citations <- function( output <- match.arg(output) if (output == "data.frame") { - bibentries %>% dplyr::mutate(citation = purrr::map_chr(bibentry, format)) + bibentries %>% dplyr::mutate(citation = purrr::map_chr(.data$bibentry, format)) } else if (output == "bibtex") { bibtex_list <- purrr::map_chr(bibentries$bibentry, \(x) { format(x, style = "bibtex") From 487802be7fc831398d7f58254478ad4880620909 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Mon, 8 Jun 2026 12:08:42 -0700 Subject: [PATCH 6/7] remove glue dependency --- R/flux_citations.R | 17 +++++++++-------- man/flux_citations.Rd | 9 +++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/R/flux_citations.R b/R/flux_citations.R index 73dc7e7..bb46892 100644 --- a/R/flux_citations.R +++ b/R/flux_citations.R @@ -62,8 +62,7 @@ flux_citations <- function( amf_split <- stringr::str_match( by_hub$AmeriFlux$product_citation, pattern = amf_pattern - ) %>% - dplyr::as_tibble() + ) colnames(amf_split) <- c( "product_citation", "authors", @@ -72,6 +71,7 @@ flux_citations <- function( "publisher", "url" ) + amf_split <- dplyr::as_tibble(amf_split) amf <- dplyr::left_join( by_hub$AmeriFlux, @@ -89,8 +89,7 @@ flux_citations <- function( icos_split <- stringr::str_match( by_hub$ICOS$product_citation, pattern = icos_pattern - ) %>% - dplyr::as_tibble() + ) colnames(icos_split) <- c( "product_citation", "authors", @@ -98,6 +97,7 @@ flux_citations <- function( "title", "url" ) + icos_split <- dplyr::as_tibble(icos_split) icos <- dplyr::left_join( by_hub$ICOS, icos_split, @@ -116,9 +116,9 @@ flux_citations <- function( tern_split <- stringr::str_match( by_hub$TERN$product_citation, pattern = tern_pattern - ) %>% - dplyr::as_tibble() + ) colnames(tern_split) <- c("product_citation", "authors", "year", "title") + tern_split <- dplyr::as_tibble(tern_split) tern <- dplyr::left_join( by_hub$TERN, tern_split, @@ -175,9 +175,10 @@ flux_citations <- function( bibtex_list <- purrr::map_chr(bibentries$bibentry, \(x) { format(x, style = "bibtex") }) - bibtex_text <- glue::glue_collapse(bibtex_list, sep = "\n") + bibtex_text <- paste0(bibtex_list, collapse = "\n") if (is.null(bibtex_path)) { - return(bibtex_text) + cat(bibtex_text) # print with nice formatting + return(invisible(bibtex_text)) # return character atomic vector } else { writeLines(bibtex_text, bibtex_path) } diff --git a/man/flux_citations.Rd b/man/flux_citations.Rd index 913dbc5..538ab76 100644 --- a/man/flux_citations.Rd +++ b/man/flux_citations.Rd @@ -7,7 +7,7 @@ flux_citations( site_ids, output = c("data.frame", "bibtex"), - output_path = NULL, + bibtex_path = NULL, ... ) } @@ -17,11 +17,11 @@ flux_citations( \item{output}{Either \code{"data.frame"} to return a tibble or \code{"bibtex"} to return (or write) BibTeX entries. See '\strong{Value}' for more details.} -\item{...}{Additional arguments passed to \code{\link[=flux_listall]{flux_listall()}}.} - \item{bibtex_path}{Path to a .bib file to write BibTeX to, passed to the \code{con} argument of \code{\link[=writeLines]{writeLines()}}. If \code{NULL} (default), BibTeX will be returned as character. Has no effect if \code{output = 'data.frame'}.} + +\item{...}{Additional arguments passed to \code{\link[=flux_listall]{flux_listall()}}.} } \value{ If \code{output = 'data.frame'}, a \code{tibble} is returned with a @@ -36,7 +36,6 @@ Given a vector of site IDs, this either returns a dataframe with or BibTeX citations for each site. } \examples{ - # Return dataframe with bibentries and formatted citations flux_citations(c("AR-Bal", "DE-Gwg")) @@ -45,13 +44,11 @@ flux_citations(c("AR-Bal", "DE-Gwg"), output = "bibtex") # Append BibTeX entries to a file \dontrun{ - flux_citations( c("AR-Bal", "DE-Gwg"), output = "bibtex", bibtex_path = "references.bib" ) - } } From dfff773cb0b60bd9c768ea58509966cdd8d3e957 Mon Sep 17 00:00:00 2001 From: Eric Scott Date: Tue, 9 Jun 2026 09:49:56 -0700 Subject: [PATCH 7/7] update actions to v6 --- .github/workflows/R-CMD-check.yaml | 4 ++-- .github/workflows/pkgdown.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2ad7c57..5f8147a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -30,11 +30,11 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: r-lib/actions/setup-pandoc@v2 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v6 with: python-version: "3.13" diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index bfc9f4d..2b29c92 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -23,7 +23,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: r-lib/actions/setup-pandoc@v2