Skip to content

Commit

Permalink
o added tzone and tclass functions as aliases to
Browse files Browse the repository at this point in the history
   indexTZ and indexClass, respectively. Eventually
   will Deprecate/Defunct the former.


git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/xts/pkg/xts@752 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
  • Loading branch information
jaryan committed Jan 15, 2013
1 parent e947e55 commit e4edc53
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: xts
Type: Package
Title: eXtensible Time Series
Version: 0.9-1
Date: 2012-10-05
Version: 0.9-2
Date: 2013-01-14
Author: Jeffrey A. Ryan, Joshua M. Ulrich
Depends: zoo (>= 1.7-2)
LinkingTo: zoo (>= 1.7.2)
Expand Down
12 changes: 12 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ export(CLASS)
export('CLASS<-')
export(indexFormat)
export('indexFormat<-')

export(indexClass)
export('indexClass<-')
export(tclass)
export('tclass<-')

export(indexTZ)
export('indexTZ<-')
export(tzone)
export('tzone<-')

export(convertIndex)
export(nseconds,
Expand Down Expand Up @@ -170,11 +175,18 @@ S3method(na.locf,xts)
S3method(print,xts)
S3method(print,CLASS)
S3method('CLASS<-',xts)

S3method('indexClass<-',xts)
S3method('tclass<-',xts)

S3method('indexFormat<-',xts)
S3method('indexFormat<-',xts)

S3method(indexTZ,xts)
S3method('indexTZ<-',xts)
S3method(tzone,xts)
S3method('tzone<-',xts)

S3method('index',xts)
S3method('index<-',xts)
S3method('time<-',xts)
Expand Down
4 changes: 2 additions & 2 deletions R/coredata.xts.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ function(x, user=NULL) {

if(is.null(user)) {
# Both xts and user attributes
rm.attr <- c(rm.attr,'.CLASS','.CLASSnames','.ROWNAMES', '.indexCLASS', '.indexFORMAT', '.indexTZ')
rm.attr <- c(rm.attr,'.CLASS','.CLASSnames','.ROWNAMES', '.indexCLASS', '.indexFORMAT', '.indexTZ', 'tzone', 'tclass')
xa <- x.attr[!names(x.attr) %in% rm.attr]
}
else
if(user) {
# Only user attributes
rm.attr <- c(rm.attr,'.CLASS','.CLASSnames','.ROWNAMES', '.indexCLASS', '.indexFORMAT','.indexTZ',
rm.attr <- c(rm.attr,'.CLASS','.CLASSnames','.ROWNAMES', '.indexCLASS', '.indexFORMAT','.indexTZ','tzone','tclass',
x.attr$.CLASSnames)
xa <- x.attr[!names(x.attr) %in% rm.attr]
} else {
Expand Down
9 changes: 7 additions & 2 deletions R/indexClass.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function(x,value) {
x
}

`indexClass` <-
tclass <- indexClass <-
function(x) {
class <- attr(attr(x, "index"), "tclass")
if(is.null(class))
Expand All @@ -34,12 +34,17 @@ function(x) {
class
}

`tclass<-` <-
function(x,value) {
UseMethod('tclass<-')
}

`indexClass<-` <-
function(x,value) {
UseMethod('indexClass<-')
}

`indexClass<-.xts` <-
`tclass<-.xts` <- `indexClass<-.xts` <-
function(x, value) {
if(!is.character(value) && length(value) != 1)
stop('improperly specified value for indexClass')
Expand Down
19 changes: 15 additions & 4 deletions R/indexTZ.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,32 @@ indexTZ <- function(x, ...)
UseMethod("indexTZ")
}

tzone <- function(x, ...) {
UseMethod("tzone")
}

`indexTZ<-` <- function(x, value) {
UseMethod("indexTZ<-")
}

`indexTZ<-.xts` <- function(x, value) {
`tzone<-` <- function(x, value) {
UseMethod("tzone<-")
}

`tzone<-.xts` <- `indexTZ<-.xts` <- function(x, value) {
if( is.null(value) ) value <- ""

attr(x, ".indexTZ") <- structure(value,.Names="TZ")
attr(x, ".indexTZ") <- attr(x, "tzone") <- structure(value,.Names="TZ")
attr(attr(x,"index"),"tzone") <- structure(value,.Names="TZ")
x
}

indexTZ.default <- function(x, ...) {

tzone.default <- indexTZ.default <- function(x, ...) {
attr(x, ".indexTZ")
}

indexTZ.xts <- function(x, ...)
tzone.xts <- indexTZ.xts <- function(x, ...)
{
tzone <- attr(attr(x, "index"), "tzone")
if(is.null(tzone))
Expand All @@ -52,6 +61,8 @@ indexTZ.xts <- function(x, ...)

check.TZ <- function(x, ...)
{
#if( !getOption("xts_check_TZ", FALSE))
# return()
check <- getOption("xts_check_TZ")
if( !is.null(check) && !check)
return()
Expand Down
5 changes: 5 additions & 0 deletions man/indexClass.Rd
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
\name{indexClass}
\alias{indexClass}
\alias{tclass}
\alias{indexFormat}
\alias{convertIndex}
\alias{indexClass<-}
\alias{tclass<-}
\alias{indexFormat<-}
\alias{index.xts}
\alias{index<-.xts}
Expand Down Expand Up @@ -35,6 +37,9 @@ of an xts object.
indexClass(x)
indexClass(x) <- value

tclass(x)
tclass(x) <- value

indexFormat(x)
indexFormat(x) <- value

Expand Down
12 changes: 10 additions & 2 deletions man/indexTZ.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
\alias{TimeZone}
\alias{indexTZ}
\alias{indexTZ<-}
\alias{tzone}
\alias{tzone<-}
\title{ Query the TimeZone of an xts object }
\description{
Get the TimeZone of an \code{xts} object.
}
\usage{
indexTZ(x, ...)
tzone(x, ...)

indexTZ(x) <- value
tzone(x) <- value
}
\arguments{
\item{x}{ an \code{xts} object }
Expand All @@ -27,7 +31,8 @@ attribute. This is to facilitate the transition to
removing the xts-specific attributes referenced by
\code{indexTZ}, \code{indexFormat}, and \code{indexClass}.
These accessor functions will continue to behave the
same under the new internals.
same under the new internals. Additionally, there is a new
getter/setter method with \code{tzone} and \code{tzone<-}.

Internally, all time indexing is converted to
POSIXct, seconds since the epoch as defined
Expand Down Expand Up @@ -60,7 +65,7 @@ of the series internally.
Problems may arise when an object that had been created under
one TZ (time zone) are used in a session using another TZ. This
isn't usually a issue, but when it is a warning is given upon printing
or subsetting.
or subsetting. This warning may be controlled with \code{option("xts_check_TZ")}.
}
\value{
A named vector of length one, giving the objects TZ at creation.
Expand All @@ -75,6 +80,9 @@ is not needed, it is often best to set the system TZ to "GMT" or
\examples{
x <- xts(1:10, Sys.Date()+1:10)
indexTZ(x)
# same, preferred as of 0.9-1
tzone(x)
str(x)
x
# now set TZ to something different...
Expand Down

0 comments on commit e4edc53

Please sign in to comment.