SCM

SCM Repository

[rmetrics] View of /pkg/timeSeries/R/timeSeries-getDataPart.R
ViewVC logotype

View of /pkg/timeSeries/R/timeSeries-getDataPart.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4396 - (download) (annotate)
Tue Sep 15 11:42:43 2009 UTC (9 years, 5 months ago) by chalabi
File size: 2739 byte(s)
! small speed improvement in the creation of new timeSeries objects.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  A copy of the GNU General Public License is available at
#  ../../COPYING


################################################################################
# S4 METHODS:               DESCRIPTION:
#  getDataPart,timeSeries    Get data slot of an object of class 'timeSeries'
#  setDataPart,timeSeries    Set data slot of an object of class 'timeSeries'
################################################################################


# this makes getDataPart a bit faster than default function


setMethod("getDataPart", "timeSeries", #"signalSeries",
    function(object)
    {
       value <- object
       attributes(value) <- NULL
       attr(value, "dim") <- attr(object, "dim")
       attr(value, "dimnames") <- attr(object, "dimnames")
       value
    }
)


# ------------------------------------------------------------------------------


# this makes setDataPart a bit faster than default function


if (getRversion() < "2.8.0") {
    setMethod("setDataPart", "timeSeries",
        function(object, value)
        {
            #-> Note : do not use as.matrix because ts objects might
            #-> not be coerced properly
            value <- as(value, "matrix")

            supplied <- attributes(object)
            valueAttrs <- attributes(value)

            supplied[names(valueAttrs)] <- valueAttrs
            # YC: force @unit to be identical to colnames(value)
            supplied[["units"]] <- colnames(value)
            attributes(value) <- supplied


            asS4(value, TRUE)
        }
    )
} else {
    setMethod("setDataPart", "timeSeries",
        function(object, value, check = TRUE)
        {
            #-> Note : do not use as.matrix because ts objects might
            #-> not be coerced properly
            if (check) value <- as(value, "matrix")

            supplied <- attributes(object)
            valueAttrs <- attributes(value)

            supplied[names(valueAttrs)] <- valueAttrs
            # YC: force @unit to be identical to colnames(value)
            supplied[["units"]] <- colnames(value)
            attributes(value) <- supplied

            asS4(value, TRUE)
        }
    )
}


################################################################################


R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge