Skip to content

Commit bbea274

Browse files
author
luke
committed
Drop dim and dimnames attributes when extending a GROWABLE vector in place.
git-svn-id: https://svn.r-project.org/R/trunk@89031 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 9419482 commit bbea274

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/main/subassign.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,17 @@ static SEXP EnlargeVector(SEXP x, R_xlen_t newlen)
162162
IS_GROWABLE(x) &&
163163
XTRUELENGTH(x) >= newlen) {
164164
SET_STDVEC_LENGTH(x, newlen);
165-
names = getNames(x);
166-
if (!isNull(names)) {
167-
SEXP newnames = EnlargeNames(names, len, newlen);
168-
if (names != newnames)
169-
setAttrib(x, R_NamesSymbol, newnames);
165+
if (ATTRIB(x) != R_NilValue) {
166+
names = getNames(x);
167+
if (!isNull(names)) {
168+
SEXP newnames = EnlargeNames(names, len, newlen);
169+
if (names != newnames)
170+
setAttrib(x, R_NamesSymbol, newnames);
171+
}
172+
if (getAttrib(x, R_DimSymbol) != R_NilValue)
173+
setAttrib(x, R_DimSymbol, R_NilValue);
174+
if (getAttrib(x, R_DimNamesSymbol) != R_NilValue)
175+
setAttrib(x, R_DimNamesSymbol, R_NilValue);
170176
}
171177
return x;
172178
}

tests/reg-tests-1e.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,15 @@ stopifnot(exprs = { ## logical/numeric mixtures:
23422342
}
23432343
})
23442344

2345+
## check that tim and dimnames are dropped when estending with GROWABLE
2346+
x <- 1:49
2347+
x[50] <- 50L
2348+
dim(x) <- c(25, 2)
2349+
dimnames(x) <- list(NULL, c("a", "b"))
2350+
a <- .Internal(address(x))
2351+
x[51] <- 51L
2352+
stopifnot(identical(a, .Internal(address(x)))) ## reused x
2353+
stopifnot(is.null(attributes(x))) ## dim and dimnames have been dropped
23452354

23462355

23472356
## keep at end

0 commit comments

Comments
 (0)