Skip to content

Commit

Permalink
add NEWS, fix all devtools::check() notes
Browse files Browse the repository at this point in the history
document quiet throughout
closes #17
add ellipses (...) to almost all functions to force named argument matching
document them in one place and inherit
  • Loading branch information
japhir committed May 3, 2024
1 parent 33d6272 commit 02ccc5f
Show file tree
Hide file tree
Showing 54 changed files with 332 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# clumpedr 0.3.0 (2024-05-03)

* Fix package install fail: the `default(quiet)` parameter didn't work because I don't export the `default` function.
* Document `quiet` once and inherit the docs everywhere. Explicitly list that it listens to `options(clumpedr.quiet)`.
* Remove all the option setting functions. Users should just use e.g., `option(clumpedr.quiet = TRUE)` if they want a global setting.
* Add `...` argument to most functions, requiring named matches (not just positions) for the more obscure function arguments.
* Remove the `pipe_plot()` function.
* Remove all references to `genplot` and plotting from the main function sources. Closes #17.
* Rebuild most tests so they work and only test one function, if possible.
* Added snapshots for tests that run the code in the vignette (ugly but it works).
* Change `.data$COLUMN` to `"COLUMN"` in all tidyselect functions such as `tidyr::pivot_*`.
* Add GitHub continuous integration.

# clumpedr 0.2.0 (2022-05-11)

* Second release to assign Zenodo DOI.

# clumpedr 0.1.0 (2021-09-14)

* First public release after codebase had somewhat stabilized.
6 changes: 5 additions & 1 deletion R/abundance_ratios.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' @param R47 Desired new name of the calculated ratio for mass 47.
#' @param R48 Desired new name of the calculated ratio for mass 48.
#' @param R49 Desired new name of the calculated ratio for mass 49.
#' @inheritParams dots
#' @inheritParams quiet
#' @export
abundance_ratios <- function(.data,
...,
Expand All @@ -24,6 +26,7 @@ abundance_ratios <- function(.data,
R45 = R45, R46 = R46, R47 = R47,
R48 = R48, R49 = R49,
quiet = NULL) {
# global variables and defaults
s44 <- s45 <- s46 <- s47 <- s48 <- s49 <- NULL

if (nrow(.data) == 0L) {
Expand All @@ -33,8 +36,9 @@ abundance_ratios <- function(.data,
quiet <- default(quiet)
}

if (!quiet)
if (!quiet) {
message("Info: calculating abundance ratios R[i] = i / 44")
}

.data %>%
mutate({{ R45 }} := {{ i45 }} / {{ i44 }},
Expand Down
5 changes: 4 additions & 1 deletion R/acid_fractionation.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @param D47 The column name of the \eqn{\Delta_47} values to use for the acid
#' fractionation calculation.
#' @param D47_out The desired new column name.
#' @inheritParams dots
#' @inheritParams quiet
#'
#' @references
#'
Expand All @@ -28,7 +30,8 @@
#' 1057--1066.
#'
#' @export
acid_fractionation <- function(.data, aff = 0.062, D47 = D47_etf,
acid_fractionation <- function(.data, aff = 0.062, ...,
D47 = D47_etf,
D47_out = D47_final,
quiet = default(quiet)) {
# global variables and defaults
Expand Down
2 changes: 2 additions & 0 deletions R/add_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#' @param .info A [tibble][tibble::tibble-package], resulting from
#' [clean_did_info()].
#' @param cols A character vector with column names in info to add to the data.
#' @inheritParams dots
#' @inheritParams quiet
#' @export
#' @family metadata cleaning functions
add_info <- function(.data, .info, ...,
Expand Down
4 changes: 3 additions & 1 deletion R/append_expected_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
#'
#' @export
#' @family empirical transfer functions
#' @inheritParams dots
#' @inheritParams quiet
append_expected_values <- function(.data,
...,
std_names = paste0("ETH-", 1:3), # we don't use ETH-4!
std_values = c(0.258, 0.256, 0.691) - 0.062, #, 0.507),
exp = expected_D47,
by = `Identifier 1`,
quiet = default(quiet)) {
quiet = NULL) {
# global variables and defaults
`Identifier 1` <- expected_D47 <- NULL

Expand Down
2 changes: 2 additions & 0 deletions R/apply_etf.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @param raw The column with raw values to apply the ETF to.
#' @param out The new column name.
#' @family empirical transfer functions
#' @inheritParams dots
#' @inheritParams quiet
#' @export
apply_etf <- function(.data, ..., intercept = intercept, slope = slope, raw = D47_raw, out = D47_etf, quiet = NULL) {
# defaults
Expand Down
2 changes: 2 additions & 0 deletions R/bulk_and_clumping_deltas.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @param d49 Column name of d49.
#' @inheritParams isobar_ratios
#' @inheritParams default.params
#' @inheritParams dots
#' @inheritParams quiet
#' @references Daeron, M., Blamart, D., Peral, M., & Affek, H. P., Absolute
#' isotopic abundance ratios and the accuracy of \eqn{\Delta_{47}}
#' measurements, _Chemical Geology_ **2016**, _442_, 83--96.
Expand Down
5 changes: 4 additions & 1 deletion R/calculate_etf.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#' @param intercept The column name of the new intercept.
#' @param parallel Whether or not (default) to process this in parallel, using package `furrr`.
#' @importFrom stats na.exclude
calculate_etf <- function(.data, raw = D47_raw_mean, exp = expected_D47,
#' @inheritParams dots
#' @inheritParams quiet
calculate_etf <- function(.data, ...,
raw = D47_raw_mean, exp = expected_D47,
session = Preparation, etf = etf,
etf_coefs = etf_coefs, slope = slope,
intercept = intercept, parallel = FALSE, quiet = NULL) {
Expand Down
4 changes: 3 additions & 1 deletion R/clean_did_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#' @seealso [isoreader::iso_read_dual_inlet()]
#' @seealso [isoreader::iso_get_file_info()]
#' @family metadata cleaning functions
clean_did_info <- function(.did, masspec = NULL,
#' @inheritParams dots
#' @inheritParams quiet
clean_did_info <- function(.did, masspec = NULL, ...,
std_names = c(paste0("ETH-", 1:4), "IAEA-C2", "Merck"),
oth_name = "other",
quiet = NULL) {
Expand Down
21 changes: 18 additions & 3 deletions R/collapse_cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' @param alpha The confidence level for the summary functions.
#' @param na.rm a logical value indicating wheter NA values should be stripped
#' before the computation proceeds.
#' @inheritParams dots
#' @inheritParams quiet
collapse_cycles <- function(.data,
...,
cols = c(d13C_PDB, d18O_PDB, D47_raw, D47_final),
Expand All @@ -19,8 +21,11 @@ collapse_cycles <- function(.data,
funs = NULL,
alpha = 0.05,
na.rm = TRUE,
quiet = default(quiet)) {
quiet = NULL) {
outlier_cycle <- d13C_PDB <- d18O_PDB <- D47_raw <- D47_final <- NULL
if (is.null(quiet)) {
quiet <- default(quiet)
}

if (!quiet) {
message("Info: collapsing cycles, calculating sample summaries.")
Expand Down Expand Up @@ -74,6 +79,8 @@ collapse_cycles <- function(.data,
#' @param flags Flag columns.
#' @param Deltas Big delta values.
#' @param p49 Param 49.
#' @inheritParams dots
#' @inheritParams quiet
#' @export
nest_cycle_data <- function(.data,
...,
Expand Down Expand Up @@ -119,17 +126,25 @@ nest_cycle_data <- function(.data,
flags = c("R45_flag", "R46_flag"),
Deltas = c("D45_raw", "D46_raw", "D47_raw",
"D48_raw", "D49_raw"),
p49 = "param_49") {
p49 = "param_49", quiet = NULL) {

if (nrow(.data) == 0L) {
return(tibble(file_id = character()))
}
if (is.null(quiet)) {
quiet <- default(quiet)
}

cols <- c("cycle", ratios, outlier_cycles, outliers, cycle_drop, bg_corrected, bgs,
Rs, deltas, isotopes, params, stochastic, flags, Deltas, p49)

if (!all(cols %in% colnames(.data)))
if (!all(cols %in% colnames(.data))) {
stop(glue::glue("columns {glue::glue_collapse(cols[!colnames(.data) %in% cols], sep=', ', last=' and ', width = 60)} not found in data"))
}

if (!quiet) {
message(glue::glue("Nesting by {glue::glue_collapse(cols, sep=', ', last=' and ', width = 60)}."))
}

.data %>%
nest(cycle_data = one_of(cols))
Expand Down
4 changes: 3 additions & 1 deletion R/correct_backgrounds.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#' @param factor Factor by which to multiply the half-cup before subtraction.
#' @param i47 Column with mass 47 intensities to correct.
#' @param i54 Column with mass 47.5 intensities to use for correction.
#' @inheritParams dots
#' @inheritParams quiet
#' @export
correct_backgrounds <- function(.data, factor,
correct_backgrounds <- function(.data, factor, ...,
i47 = v47.mV, i54 = v54.mV,
quiet = default(quiet)) {
# global variables and defaults
Expand Down
3 changes: 2 additions & 1 deletion R/delta_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#' [correct_backgrounds()].
#' @details This function is a wrapper for the [abundance_ratios()],
#' [little_deltas()], and [bulk_and_clumping_deltas()] functions.
#'
#' @inheritParams dots
#' @inheritParams quiet
#' @export
delta_values <- function(.data, ..., quiet = NULL) {
R45_wg <- R46_wg <- R47_wg <- R48_wg <- R49_wg <- NULL
Expand Down
6 changes: 5 additions & 1 deletion R/empirical_transfer_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#' then apply the ETF to all the samples and standards.
#'
#' @param .data A [tibble][tibble::tibble-package] resulting from [collapse_cycles()].
#' @param id1 Column name of `Identifier 1` (default).
#' @param outlier Column name of `outlier` (default).
#' @inheritParams append_expected_values
#' @inheritParams calculate_etf
#'
#' @inheritParams apply_etf
#' @inheritParams dots
#' @inheritParams quiet
#' @details This function is a wrapper for [append_expected_values()],
#' [calculate_etf()], and [apply_etf()].
#'
Expand Down
11 changes: 9 additions & 2 deletions R/find_bad_cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#' @param cycle Column name of the column with the measurement cycle number.
#' @param relative_to cycle Drop detection occurs relative to either the first
#' cycle ("init", default) or to the previous cycle ("prev").
#' @inheritParams dots
#' @inheritParams quiet
#' @export
#' @family cycle functions
find_bad_cycles <- function(.data, ...,
min, max, fac,
v44 = "v44.mV", cycle = "cycle",
relative_to = "init",
quiet = default(quiet)) {
quiet = NULL) {
if (nrow(.data) == 0L) {
return(tibble(file_id = character()))
}
Expand All @@ -35,6 +37,10 @@ find_bad_cycles <- function(.data, ...,
stop("'relative_to': ", relative_to, " should be eigher 'init' or 'prev'")
}

if (is.null(quiet)) {
quiet <- default(quiet)
}

out <- .data %>%
mutate(outlier_cycle_low = .data[[v44]] <= .data[[min]],
outlier_cycle_high = .data[[v44]] >= .data[[max]],
Expand Down Expand Up @@ -66,9 +72,10 @@ find_bad_cycles <- function(.data, ...,
.by = "file_id") %>%
mutate(outlier_cycle = .data$outlier_cycle_low | .data$outlier_cycle_high | .data$outlier_cycle_drop, .by = "file_id")

if (!quiet)
if (!quiet) {
glue("Info: found {length(unique(pull(filter(out, .data$cycle_has_drop), file_id)))} out of {length(unique(pull(out, file_id)))} acquisitions with a drop in pressure of mass 44.") %>%
message()
}

out
}
Loading

0 comments on commit 02ccc5f

Please sign in to comment.