Skip to content

Commit 027b572

Browse files
author
maechler
committed
array(dim = {}) error msg says 'dim'
git-svn-id: https://svn.r-project.org/R/trunk@89147 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 5a264c1 commit 027b572

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@
452452
\item The implicitGeneric definition for \code{toeplitz()} produced a
453453
default method that failed when \code{toeplitz(x, r)} was called with
454454
more than the first argument. Simple fix from \I{Mikael Jagan}.
455+
456+
\item The error message for \code{array(dim = c())} now uses
457+
\code{"'dim'"}, thanks to \I{Hugo Gruson}.
455458
}
456459
}
457460
}

src/main/array.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,11 +2144,8 @@ attribute_hidden SEXP do_colsum(SEXP call, SEXP op, SEXP args, SEXP rho)
21442144
/* array(data, dim, dimnames) */
21452145
attribute_hidden SEXP do_array(SEXP call, SEXP op, SEXP args, SEXP rho)
21462146
{
2147-
SEXP vals, ans, dims, dimnames;
2148-
R_xlen_t lendat, i, nans;
2149-
21502147
checkArity(op, args);
2151-
vals = CAR(args); // = data
2148+
SEXP vals = CAR(args); // = data
21522149
/* at least NULL can get here */
21532150
switch(TYPEOF(vals)) {
21542151
case LGLSXP:
@@ -2164,20 +2161,21 @@ attribute_hidden SEXP do_array(SEXP call, SEXP op, SEXP args, SEXP rho)
21642161
error(_("'data' must be of a vector type, was '%s'"),
21652162
R_typeToChar(vals));
21662163
}
2167-
lendat = XLENGTH(vals);
2168-
dims = CADR(args);
2169-
dimnames = CADDR(args);
2164+
SEXP ans,
2165+
dims = CADR(args),
2166+
dimnames = CADDR(args);
21702167
PROTECT(dims = coerceVector(dims, INTSXP));
21712168
int nd = LENGTH(dims);
2172-
if (nd == 0) error(_("'dims' cannot be of length 0"));
2169+
if (nd == 0) error(_("'dim' cannot be of length 0"));
21732170
double d = 1.0;
21742171
for (int j = 0; j < nd; j++) d *= INTEGER(dims)[j];
21752172
#ifdef LONG_VECTOR_SUPPORT
21762173
if (d > R_XLEN_T_MAX) error(_("too many elements specified"));
21772174
#else
21782175
if (d > INT_MAX) error(_("too many elements specified"));
21792176
#endif
2180-
nans = (R_xlen_t) d;
2177+
R_xlen_t lendat = XLENGTH(vals),
2178+
i, nans = (R_xlen_t) d;
21812179

21822180
PROTECT(ans = allocVector(TYPEOF(vals), nans));
21832181
switch(TYPEOF(vals)) {

tests/reg-tests-1e.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,15 @@ x["a"] <- 100; chk1d(x)
24622462
## x["a"] <- .. did drop dim() & dimnames() {getting names() instead}.
24632463

24642464

2465+
## error message when length(dim) == 0:
2466+
(m1 <- tryCmsg(array(NULL )))
2467+
(m2 <- tryCmsg(array(,NULL)))
2468+
if(englishMsgs)
2469+
stopifnot(grepl(" was 'NULL'", m1, fixed=TRUE),
2470+
grepl("'dim' cannot ", m2, fixed=TRUE))
2471+
## had 'dims'
2472+
2473+
24652474

24662475
## keep at end
24672476
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)