[R] Age of an object?
Martin Maechler
maechler at stat.math.ethz.ch
Wed Dec 14 15:53:26 CET 2005
>>>>> "Roger" == Roger Bivand <Roger.Bivand at 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 at gmail.com>
>> >>>>> on Wed, 14 Dec 2005 08:59:24 -0400 writes:
>>
Kjetil> Philippe Grosjean wrote:
>> >> Martin Maechler wrote:
>> >>>>>>>> "Trevor" == Trevor Hastie <hastie at 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
More information about the R-help
mailing list