Skip to content

Commit

Permalink
allow skip.fails in calc_addVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
orichters committed Mar 28, 2024
1 parent e8b4d76 commit ee75257
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '618891372'
ValidationKey: '619854900'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'quitte: Bits and pieces of code to use with quitte-style data frames'
version: 0.3128.4
date-released: '2024-03-01'
version: 0.3129.0
date-released: '2024-03-28'
abstract: A collection of functions for easily dealing with quitte-style data frames,
doing multi-model comparisons and plots.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: quitte
Title: Bits and pieces of code to use with quitte-style data frames
Version: 0.3128.4
Date: 2024-03-01
Version: 0.3129.0
Date: 2024-03-28
Authors@R: c(
person("Michaja", "Pehl", , "[email protected]", role = c("aut", "cre")),
person("Nico", "Bauer", , "[email protected]", role = "aut"),
Expand Down
20 changes: 13 additions & 7 deletions R/calc_addVariable.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#' @param overwrite If `TRUE` (the default), values are overwritten if they
#' already exist. If `FALSE` values are discarded and not overwritten if they
#' already exist
#' @param skip.fails If `FALSE` (the default), fail if any right-hand-side variable is missing
#' If `TRUE`, just skip that calculation.
#' @param .dots Used to work around non-standard evaluation. See details.
#'
#' @return A data frame.
Expand Down Expand Up @@ -93,7 +95,7 @@
calc_addVariable <- function(data, ..., units = NA, na.rm = TRUE,
completeMissing = FALSE, only.new = FALSE,
variable = variable, unit = unit,
value = value, overwrite = TRUE) {
value = value, overwrite = TRUE, skip.fails = FALSE) {

.dots <- list(...)

Expand All @@ -113,15 +115,15 @@ calc_addVariable <- function(data, ..., units = NA, na.rm = TRUE,
value <- deparse(substitute(value))

calc_addVariable_(data, .dots, na.rm, completeMissing, only.new, variable,
unit, value, overwrite)
unit, value, overwrite, skip.fails)
}

#' @export
#' @rdname calc_addVariable
calc_addVariable_ <- function(data, .dots, na.rm = TRUE,
completeMissing = FALSE, only.new = FALSE,
variable = 'variable', unit = 'unit',
value = 'value', overwrite = TRUE) {
value = 'value', overwrite = TRUE, skip.fails = FALSE) {
. <- NULL

# guardians ----
Expand Down Expand Up @@ -181,10 +183,14 @@ calc_addVariable_ <- function(data, .dots, na.rm = TRUE,
missing_rhs_variables <- setdiff(.dots[[i]]$variables,
data_work[[variable]])
if (0 < length(missing_rhs_variables)) {
stop(length(missing_rhs_variables), ' variable',
ifelse(1 < length(missing_rhs_variables), 's are', ' is'),
' missing for the calculation:\n',
paste(paste0('`', missing_rhs_variables, '`'), collapse = '\n'))
if (isTRUE(skip.fails)) {
next
} else {
stop(length(missing_rhs_variables), ' variable',
ifelse(1 < length(missing_rhs_variables), 's are', ' is'),
' missing for the calculation:\n',
paste(paste0('`', missing_rhs_variables, '`'), collapse = '\n'))
}
}

data_work <- bind_rows(
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bits and pieces of code to use with quitte-style data frames

R package **quitte**, version **0.3128.4**
R package **quitte**, version **0.3129.0**

[![CRAN status](https://www.r-pkg.org/badges/version/quitte)](https://cran.r-project.org/package=quitte) [![R build status](https://github.com/pik-piam/quitte/workflows/check/badge.svg)](https://github.com/pik-piam/quitte/actions) [![codecov](https://codecov.io/gh/pik-piam/quitte/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/quitte) [![r-universe](https://pik-piam.r-universe.dev/badges/quitte)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -47,7 +47,7 @@ In case of questions / problems please contact Michaja Pehl <michaja.pehl@pik-po

To cite package **quitte** in publications use:

Pehl M, Bauer N, Hilaire J, Levesque A, Luderer G, Schultes A, Dietrich J, Richters O (2024). _quitte: Bits and pieces of code to use with quitte-style data frames_. R package version 0.3128.4, <URL: https://github.com/pik-piam/quitte>.
Pehl M, Bauer N, Hilaire J, Levesque A, Luderer G, Schultes A, Dietrich J, Richters O (2024). _quitte: Bits and pieces of code to use with quitte-style data frames_. R package version 0.3129.0, <URL: https://github.com/pik-piam/quitte>.

A BibTeX entry for LaTeX users is

Expand All @@ -56,7 +56,7 @@ A BibTeX entry for LaTeX users is
title = {quitte: Bits and pieces of code to use with quitte-style data frames},
author = {Michaja Pehl and Nico Bauer and Jérôme Hilaire and Antoine Levesque and Gunnar Luderer and Anselm Schultes and Jan Philipp Dietrich and Oliver Richters},
year = {2024},
note = {R package version 0.3128.4},
note = {R package version 0.3129.0},
url = {https://github.com/pik-piam/quitte},
}
```
9 changes: 7 additions & 2 deletions man/calc_addVariable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee75257

Please sign in to comment.