Re: [R] Age of an object?

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu 15 Dec 2005 - 01:53:26 EST

>>>>> "Roger" == Roger Bivand <Roger.Bivand@nhh.no> >>>>> on Wed, 14 Dec 2005 15:14:47 +0100 (CET) writes:

    Roger> On Wed, 14 Dec 2005, Martin Maechler wrote:

>> >>>>> "Kjetil" == Kjetil Brinchmann Halvorsen <kjetilbrinchmannhalvorsen@gmail.com>
>> >>>>> on Wed, 14 Dec 2005 08:59:24 -0400 writes:
>>
    Kjetil> Philippe Grosjean wrote:
>> >> Martin Maechler wrote:
>> >>>>>>>> "Trevor" == Trevor Hastie <hastie@stanford.edu>
>> >>>>>>>> on Tue, 13 Dec 2005 12:51:34 -0800 writes:
>> >>>
    Trevor> It would be nice to have a date stamp on an object.
>>

    Kjetil> Following up on my post of a few minutes ago, I tried to write an     Kjetil> timestamp function
>>
    Kjetil> timestamp <- function(obj, moretext){
    Kjetil> comment(obj) <<- paste(Sys.time(), moretext, sep="\n")
    Kjetil> }

>>

    Kjetil> but this does'nt work.
>>
>> >> myobj <- 1:10
>> >> timestamp(myobj, "test")
    Kjetil> Error in timestamp(myobj, "test") : object "obj" not found
>> >>
>>
>> Instead, I'd **strongly** recommend to define *two* functions,
>> one "constructor" and one "inspector" :
>>
>> "timestamp<-" <- function(obj, value) {
>> stamp <- paste(Sys.time(), value)
>> ## attr(obj,"timestamp") <- stamp
>> comment(obj) <- stamp
>> obj
>> }

    Roger> This does treat any existing comment rather brutally, could stamp rather     Roger> be:

    Roger> stamp <- paste(Sys.time(), comment(obj), value)

    Roger> probably enhanced with some field separators to let the inspector grab     Roger> just its chunk? Something like DCF?

Sure (and hence Duncan TL's answer).
My main point was to define a "timestamp<-" function and use

    timestamp(......) <- ....

[instead of using functions that silently modify their arguments..]

Martin



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Dec 15 02:25:55 2005

This archive was generated by hypermail 2.1.8 : Thu 15 Dec 2005 - 04:31:54 EST