Skip to content

Commit 923beaa

Browse files
committed
improve cbind arg name deparsing
1 parent da91301 commit 923beaa

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: quantities
22
Type: Package
33
Title: Quantity Calculus for R Vectors
4-
Version: 0.2.3
4+
Version: 0.2.3.1
55
Authors@R: c(
66
person("Iñaki", "Ucar", email="iucar@fedoraproject.org",
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+
# quantities devel
2+
3+
- Improve `cbind` arg name deparsing.
4+
15
# quantities 0.2.3
26

37
- Fixes for `covar` and `correl` implementations.

R/misc.R

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,10 @@ t.quantities <- function(x) reclass(NextMethod())
152152
#'
153153
#' @export
154154
cbind.quantities <- function(..., deparse.level = 1) {
155-
dots <- list(...)
155+
dots <- .deparse(list(...), substitute(list(...)), deparse.level)
156156
stopifnot(all(sapply(dots, inherits, "units")))
157157
u <- units(dots[[1]])
158158
dots <- lapply(dots, set_units, u, mode="standard")
159-
160-
nm <- names(as.list(match.call()))
161-
nm <- nm[nm != "" & nm != "deparse.level"]
162-
if (is.null(nm))
163-
names(dots) <- sapply(substitute(list(...))[-1], deparse)
164-
else names(dots) <- nm
165-
166159
call <- as.character(match.call()[[1]])
167160
assign(call, getS3method(call, "errors"))
168161
value <- do.call(call, c(dots, deparse.level=deparse.level))

R/utils.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,23 @@ dfapply <- function(X, FUN, ...) {
1010
attributes(X) <- attrs
1111
X
1212
}
13+
14+
.deparse <- function(dots, symarg, deparse.level) {
15+
deparse.level <- as.integer(deparse.level)
16+
if (identical(deparse.level, -1L)) deparse.level <- 0L # R Core's hack
17+
stopifnot(0 <= deparse.level, deparse.level <= 2)
18+
19+
nm <- c( ## 0:
20+
function(i) NULL,
21+
## 1:
22+
function(i) if(is.symbol(s <- symarg[[i]])) deparse(s) else NULL,
23+
## 2:
24+
function(i) deparse(symarg[[i]])[[1L]])[[ 1L + deparse.level ]]
25+
Nms <- function(i) { if(!is.null(s <- names(symarg)[i]) && nzchar(s)) s else nm(i) }
26+
27+
symarg <- as.list(symarg)[-1L]
28+
dnames <- sapply(seq_along(dots), Nms)
29+
if (!all(sapply(dnames, is.null)))
30+
names(dots) <- dnames
31+
dots
32+
}

0 commit comments

Comments
 (0)