Skip to content

Commit

Permalink
Fix subset.range for yearmon index
Browse files Browse the repository at this point in the history
Subsetting would fail when the plotted object has a yearmon index,
because the start/end index values are converted to character as the
3-letter month abbreviation and the 4-digit year. That is not a valid
ISO-8601 range string, as shown in the example below.

    x <- apply.monthly(as.xts(sample_matrix[,4]), last)
    index(x) <- as.yearmon(index(x))
    paste(start(x), end(x), sep = "/")
    [1] "Jan 2007/Jun 2007"

Explicitly format the start/end index values as ISO-8601 before
combining them into the range string.

Fixes #353.
  • Loading branch information
joshuaulrich committed Jun 13, 2021
1 parent 2370446 commit 81ef49a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,10 @@ addEventLines <- function(events, main="", on=0, lty=1, lwd=1, col=1, ...){
}
ypos <- x$Env$ylim[[2*on]][2]*0.995
# we can add points that are not necessarily at the points on the main series
subset.range <- paste(start(xdata[xsubset]),
end(xdata[xsubset]),sep="/")
subset.range <-
paste(format(start(xdata[xsubset]), "%Y%m%d %H:%M:%OS6"),
format(end(xdata[xsubset]), "%Y%m%d %H:%M:%OS6"),
sep = "/")
ta.adj <- merge(n=.xts(1:NROW(xdata[xsubset]),
.index(xdata[xsubset]),
tzone=tzone(xdata)),
Expand Down

0 comments on commit 81ef49a

Please sign in to comment.