Skip to content

Commit

Permalink
performance improvements in data.frame methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Dec 6, 2023
1 parent 88b9ea3 commit cc2f192
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: errors
Type: Package
Title: Uncertainty Propagation for R Vectors
Version: 0.4.0.2
Version: 0.4.1
Authors@R: c(
person("Iñaki", "Ucar", email="[email protected]",
role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550")),
Expand All @@ -20,6 +20,6 @@ LazyData: true
Depends: R (>= 3.0.0)
Suggests: dplyr (>= 1.0.0), vctrs (>= 0.5.0), pillar, ggplot2 (>= 3.4.0),
testthat, vdiffr, knitr, rmarkdown
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Roxygen: list(old_usage = TRUE)
VignetteBuilder: knitr
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# errors 0.4.0.2
# errors 0.4.1

- Switch from `size` (deprecated in `ggplot2` v3.4.0) to `linewidth` aesthetic
in `geom_errors()` (#55).
- Implement methods for dealing with missing values in `errors` objects,
and fix `na.rm` behavior for summary methods (#56).
- Performance improvements for `data.frame` methods.

# errors 0.4.0

Expand Down
6 changes: 1 addition & 5 deletions R/errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,5 @@ drop_errors.errors <- function(x) {
#' @name drop_errors
#' @export
drop_errors.data.frame <- function(x) {
for (i in seq_along(x)) {
if (inherits(x[[i]], "errors"))
x[[i]] <- drop_errors(x[[i]])
}
x
dfapply(x, function(i) if (inherits(i, "errors")) drop_errors(i) else i)
}
5 changes: 1 addition & 4 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,10 @@ diff.errors <- function(x, lag = 1L, differences = 1L, ...) {
as.data.frame.errors <- function(x, row.names = NULL, optional = FALSE, ...) {
e <- .e(x)
dim(e) <- dim(x)
e <- as.data.frame(e)
xx <- as.data.frame(unclass(x), row.names, optional, ...)
if (!optional && ncol(xx) == 1)
colnames(xx) <- deparse(substitute(x))
for (i in seq_len(ncol(xx)))
errors(xx[[i]]) <- e[[i]]
xx
df2apply(xx, as.data.frame(e), set_errors)
}

#' Coerce to a List
Expand Down
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,17 @@ cond2int <- function(...) {
args <- c(...)
sum(2^(seq_along(args) - 1) * args)
}

dfapply <- function(X, FUN, ...) {
attrs <- attributes(X)
X <- lapply(X, FUN, ...)
attributes(X) <- attrs
X
}

df2apply <- function(X, Y, FUN, ...) {
attrs <- attributes(X)
X <- mapply(FUN, X, Y, ..., SIMPLIFY=FALSE)
attributes(X) <- attrs
X
}
6 changes: 3 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Minor release
## Patch release

Several fixes an improvements for errorbars for base plot and ggplot2.
Several fixes an improvements.

## Test environments

Expand All @@ -14,4 +14,4 @@ There were no ERRORs, WARNINGs or NOTEs.
## Downstream dependencies

There are two downstream dependencies, quantities and constants, for which I'm
the maintainer too. An update for quantities is required.
the maintainer too. No issues detected.
5 changes: 3 additions & 2 deletions man/cbind.errors.Rd

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

0 comments on commit cc2f192

Please sign in to comment.