Skip to content

Commit

Permalink
Make .xts() not return an object with row names
Browse files Browse the repository at this point in the history
.xts() would return an object with row names when passed a matrix with
row names. But xts objects never have a 'rownames' attribute.

Fixes #298.
  • Loading branch information
joshuaulrich committed Aug 2, 2020
1 parent 926453e commit d0b7e8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ function(x=NULL, index, tclass=c("POSIXct","POSIXt"),
xx <- .Call("add_xtsCoreAttributes", x, index, tzone, tclass,
c('xts','zoo'), tformat, PACKAGE='xts')

# ensure there are no rownames
if(!is.null((dimnames(xx)))) {
dimnames(xx)[[1]] <- NULL
}

# remove any index attributes that came through '...'
# and set any user attributes (and/or dim, dimnames, etc)
dots.names <- eval(substitute(alist(...)))
Expand Down
6 changes: 6 additions & 0 deletions inst/unitTests/runit.xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ test..xts_dimnames_in_dots <- function() {
checkEquals(x, y)
}

test..xts_ctor_does_not_return_rownames <- function() {
m <- matrix(1, dimnames = list("a", "b"))
x <- .xts(m, 1)
checkEquals(rownames(x), NULL)
}

test..xts_ctor_warns_if_index_tclass_not_NULL_or_POSIXct <- function() {
DEACTIVATED("Warning causes errors in dependencies")
op <- options(warn = 2)
Expand Down

0 comments on commit d0b7e8d

Please sign in to comment.