[Xts-commits] r728 - in pkg/xts: R inst/doc
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Sep 4 00:07:52 CEST 2012
Author: bodanker
Date: 2012-09-04 00:07:52 +0200 (Tue, 04 Sep 2012)
New Revision: 728
Modified:
pkg/xts/R/toperiod.R
pkg/xts/inst/doc/xts-faq.Rnw
Log:
- Add %\VignetteIndexEntry{xts FAQ} to the xts FAQ
- overhaul .drop.time
Modified: pkg/xts/R/toperiod.R
===================================================================
--- pkg/xts/R/toperiod.R 2012-08-31 16:18:01 UTC (rev 727)
+++ pkg/xts/R/toperiod.R 2012-09-03 22:07:52 UTC (rev 728)
@@ -186,16 +186,20 @@
`.drop.time` <-
function(x) {
# function to remove HHMMSS portion of time index
- if(!inherits(x,"its")) {
- x <- as.xts(x)
- current.indexClass <- indexClass(x)
- if(any(current.indexClass=='POSIXt')) {
- indexClass(x) <- "Date"
- index(x) <- index(x) # convert index to Date
- #reclass(x)
+ xts.in <- is.xts(x) # is the input xts?
+ if(!xts.in) # if not, try to convert to xts
+ x <- try.xts(x, error=FALSE)
+ if(is.xts(x)) {
+ # if x is xts, drop HHMMSS from index
+ if(any(indexClass(x)=='POSIXt')) {
+ indexClass(x) <- "Date" # set indexClass to Date
}
- x
- } else x
+ # force conversion, even if we didn't set indexClass to Date
+ # because indexAt yearmon/yearqtr won't drop time from index
+ index(x) <- index(x)
+ if(xts.in) x # if input already was xts
+ else reclass(x) # if input wasn't xts, but could be converted
+ } else x # if input wasn't xts, and couldn't be converted
}
`by.period` <-
function(x, FUN, on=Cl, period="days", k=1, fill=na.locf, ...) {
Modified: pkg/xts/inst/doc/xts-faq.Rnw
===================================================================
--- pkg/xts/inst/doc/xts-faq.Rnw 2012-08-31 16:18:01 UTC (rev 727)
+++ pkg/xts/inst/doc/xts-faq.Rnw 2012-09-03 22:07:52 UTC (rev 728)
@@ -9,6 +9,7 @@
% \vskip \postSskip \nopagebreak}
%% -*- encoding: utf-8 -*-
+%\VignetteIndexEntry{xts FAQ}
\documentclass{article}
%
\usepackage{Rd}
More information about the Xts-commits
mailing list