From Martin Maechler <maechler@stat.math.ethz.ch>  Wed Sep 30 15:40:06 1998
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Wed, 30 Sep 1998 16:40:06 +0200
Subject: "tsp<-"
In-Reply-To: <98Sep28.153343edt.13470@mailgate.bank-banque-canada.ca> (message
 from Paul Gilbert on Mon, 28 Sep 1998 15:30:03 -0400)
Message-ID: <199809301440.QAA04028@florence.ethz.ch>

Thank you, Paul, for reporting this problem:

>>>>> "PaulG" == Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:

    PaulG> If value is NULL I think tsp assignment should not return a
    PaulG> class ts object.  Below is a fixed version.

	"tsp<-" <-function(x, value)
	{if (is.null(value))
	   {attr(x, "tsp") <- value
	    if(inherits(x,"ts")) class(x) <- NULL
	    return(x)
	   }
	 attr(x, "tsp") <-  value
	 class(x) <- "ts"
	 x
	}


Shouldn't we be even more restrictive?

 The tsp attribute (hance "value" above) should be
     - numeric
     - of length 3

And then, I'd rather stop the user than destroy the class of my ts object?!
i.e.

"tsp<-" <- function(x, value)
{
    if(!(is.numeric(value) && length(value) == 3))
        stop("invalid 'tsp': must be numeric of length 3")
    attr(x,"tsp") <- value
    x
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


"tsp<-"
Martin Maechler