Skip to content

Commit

Permalink
Handle 'x' and 'xout' args in na.locf.xts()
Browse files Browse the repository at this point in the history
The na.locf.xts() method did not support 'x' and 'xout', like the
default method does. The easiest way to support these arguments is to
check if they're part of the call, then punt to the next method if
they are.

Fixes #215.
  • Loading branch information
joshuaulrich committed Mar 11, 2018
1 parent 0d80977 commit 5f4fef1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/na.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ na.locf.xts <- function(object, na.rm=FALSE, fromLast=FALSE, maxgap=Inf, ...) {
maxgap <- min(maxgap, NROW(object))
if(length(object) == 0)
return(object)
if(hasArg("x") || hasArg("xout"))
return(NextMethod())
if(dim(object)[2] > 1) {
x <- object
for(n in 1:NCOL(object))
Expand Down
15 changes: 15 additions & 0 deletions inst/unitTests/runit.na.locf.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ test.nalocf_fromLast <- function() {
z <- na.locf(zdat, fromLast = TRUE)
checkEquals(x, as.xts(z), check.attributes = TRUE)
}

test.nalocf_x <- function() {
xidx <- rbind(xidx, .xts(0, 30))
zidx <- as.zoo(xidx)

x <- na.locf(xdat, x = index(xidx))
z <- na.locf(zdat, x = index(zidx))
checkEquals(x, as.xts(z), check.attributes = TRUE)
}

test.nalocf_xout <- function() {
x <- na.locf(xdat, xout = index(xidx))
z <- na.locf(zdat, xout = index(zidx))
checkEquals(x, as.xts(z), check.attributes = TRUE)
}

0 comments on commit 5f4fef1

Please sign in to comment.