Skip to content

Commit 2b4e82c

Browse files
committed
improve cbind arg name deparsing
1 parent 191d5c1 commit 2b4e82c

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
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.3
4+
Version: 0.4.3.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")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# errors devel
2+
3+
- Improve `cbind` arg name deparsing.
4+
15
# errors 0.4.3
26

37
- Add option `decimals` to `format()` method to add support for uncertainty with

R/misc.R

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,16 @@ t.errors <- function(x) {
195195
#'
196196
#' @export
197197
cbind.errors <- function(..., deparse.level = 1) {
198-
call <- as.character(match.call()[[1]])
199-
allargs <- lapply(list(...), unclass)
200-
nm <- names(as.list(match.call()))
201-
nm <- nm[nm != "" & nm != "deparse.level"]
202-
if (is.null(nm))
203-
names(allargs) <- sapply(substitute(list(...))[-1], deparse)
204-
else names(allargs) <- nm
205-
allerrs <- lapply(list(...), function(x) {
198+
dots <- .deparse(list(...), substitute(list(...)), deparse.level)
199+
errs <- lapply(dots, function(x) {
206200
e <- .e(x)
207201
dim(e) <- dim(x)
208202
e
209203
})
204+
call <- as.character(match.call()[[1]])
210205
set_errors(
211-
do.call(call, c(allargs, deparse.level=deparse.level)),
212-
as.numeric(do.call(call, allerrs))
206+
do.call(call, c(lapply(dots, unclass), deparse.level=deparse.level)),
207+
as.numeric(do.call(call, c(errs, deparse.level=0)))
213208
)
214209
}
215210

R/utils.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,23 @@ df2apply <- function(X, Y, FUN, ...) {
9595
attributes(X) <- attrs
9696
X
9797
}
98+
99+
.deparse <- function(dots, symarg, deparse.level) {
100+
deparse.level <- as.integer(deparse.level)
101+
if (identical(deparse.level, -1L)) deparse.level <- 0L # R Core's hack
102+
stopifnot(0 <= deparse.level, deparse.level <= 2)
103+
104+
nm <- c( ## 0:
105+
function(i) NULL,
106+
## 1:
107+
function(i) if(is.symbol(s <- symarg[[i]])) deparse(s) else NULL,
108+
## 2:
109+
function(i) deparse(symarg[[i]])[[1L]])[[ 1L + deparse.level ]]
110+
Nms <- function(i) { if(!is.null(s <- names(symarg)[i]) && nzchar(s)) s else nm(i) }
111+
112+
symarg <- as.list(symarg)[-1L]
113+
dnames <- sapply(seq_along(dots), Nms)
114+
if (!all(sapply(dnames, is.null)))
115+
names(dots) <- dnames
116+
dots
117+
}

0 commit comments

Comments
 (0)