-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore row.date if as.zoo is called with order.by
quantmod:::as.zoo.data.frame() was added in c2f9916, on 2007-07-01. The zoo package did not have an as.zoo.data.frame() method until 2010-08-03. The quantmod method always assumes rownames should be used for the index of the zoo object, either by converting them to Date or using them as raw characters. But the zoo method will use a plain integer index and assume the data are sorted if the user doesn't explicitly provide an order.by argument. Fixes #168.
- Loading branch information
1 parent
19cd7b6
commit 28c1982
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Call as.zoo before quantmod is loaded and registers its S3 method | ||
dc <- c("2015-01-01", "2016-01-01", "2017-01-01") | ||
dd <- as.Date(dc) | ||
|
||
f <- data.frame(a = 1:3) | ||
r <- f | ||
rownames(r) <- dc | ||
|
||
zz.f.date <- zoo::as.zoo(f, order.by = dd) | ||
zz.f.char <- zoo::as.zoo(f, order.by = dc) | ||
zz.f <- zoo::as.zoo(f) | ||
|
||
zz.r.date <- zoo::as.zoo(r, order.by = dd) | ||
zz.r.char <- zoo::as.zoo(r, order.by = dc) | ||
zz.r <- zoo::as.zoo(r) | ||
|
||
library(quantmod) | ||
|
||
### quantmod:::as.zoo.data.frame | ||
|
||
# should be the same as zoo:::as.zoo.data.frame when order.by is provided | ||
stopifnot(identical(zz.f.char, as.zoo(f, order.by = dc))) | ||
stopifnot(identical(zz.f.date, as.zoo(f, order.by = dd))) | ||
stopifnot(identical(zz.r.char, as.zoo(r, order.by = dc))) | ||
stopifnot(identical(zz.r.date, as.zoo(r, order.by = dd))) |