Skip to content

Commit cc2f192

Browse files
committed
performance improvements in data.frame methods
1 parent 88b9ea3 commit cc2f192

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: errors
22
Type: Package
33
Title: Uncertainty Propagation for R Vectors
4-
Version: 0.4.0.2
4+
Version: 0.4.1
55
Authors@R: c(
66
person("Iñaki", "Ucar", email="[email protected]",
77
role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550")),
@@ -20,6 +20,6 @@ LazyData: true
2020
Depends: R (>= 3.0.0)
2121
Suggests: dplyr (>= 1.0.0), vctrs (>= 0.5.0), pillar, ggplot2 (>= 3.4.0),
2222
testthat, vdiffr, knitr, rmarkdown
23-
RoxygenNote: 7.2.2
23+
RoxygenNote: 7.2.3
2424
Roxygen: list(old_usage = TRUE)
2525
VignetteBuilder: knitr

NEWS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# errors 0.4.0.2
1+
# errors 0.4.1
22

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

89
# errors 0.4.0
910

R/errors.R

+1-5
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,5 @@ drop_errors.errors <- function(x) {
232232
#' @name drop_errors
233233
#' @export
234234
drop_errors.data.frame <- function(x) {
235-
for (i in seq_along(x)) {
236-
if (inherits(x[[i]], "errors"))
237-
x[[i]] <- drop_errors(x[[i]])
238-
}
239-
x
235+
dfapply(x, function(i) if (inherits(i, "errors")) drop_errors(i) else i)
240236
}

R/misc.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,10 @@ diff.errors <- function(x, lag = 1L, differences = 1L, ...) {
125125
as.data.frame.errors <- function(x, row.names = NULL, optional = FALSE, ...) {
126126
e <- .e(x)
127127
dim(e) <- dim(x)
128-
e <- as.data.frame(e)
129128
xx <- as.data.frame(unclass(x), row.names, optional, ...)
130129
if (!optional && ncol(xx) == 1)
131130
colnames(xx) <- deparse(substitute(x))
132-
for (i in seq_len(ncol(xx)))
133-
errors(xx[[i]]) <- e[[i]]
134-
xx
131+
df2apply(xx, as.data.frame(e), set_errors)
135132
}
136133

137134
#' Coerce to a List

R/utils.R

+14
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ cond2int <- function(...) {
7272
args <- c(...)
7373
sum(2^(seq_along(args) - 1) * args)
7474
}
75+
76+
dfapply <- function(X, FUN, ...) {
77+
attrs <- attributes(X)
78+
X <- lapply(X, FUN, ...)
79+
attributes(X) <- attrs
80+
X
81+
}
82+
83+
df2apply <- function(X, Y, FUN, ...) {
84+
attrs <- attributes(X)
85+
X <- mapply(FUN, X, Y, ..., SIMPLIFY=FALSE)
86+
attributes(X) <- attrs
87+
X
88+
}

cran-comments.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Minor release
1+
## Patch release
22

3-
Several fixes an improvements for errorbars for base plot and ggplot2.
3+
Several fixes an improvements.
44

55
## Test environments
66

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

1616
There are two downstream dependencies, quantities and constants, for which I'm
17-
the maintainer too. An update for quantities is required.
17+
the maintainer too. No issues detected.

man/cbind.errors.Rd

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)