Skip to content
Prev 75450 / 398502 Next

Dating Objects

Paul Roebuck wrote:

        
On Fri, 12 Aug 2005, Jason Skelton wrote:

            
I don't follow what you aren't following ....  It seems to me
	to be an eminently reasonable thing to want to do.  Answers
	questions such as ``Was x modified since y was modified?''

	Presumably modification date is what's wanted; this is the
	crucial concept.  One could tack on a creation date as well ...

	I think I would make the modification data an ***attribute***
	of the object, rather than sticking it in as a component.
	(The latter might mess up some vital aspect of the nature
	of the object.)

	The problem is to remember to date stamp each object each
	time it is modified ....

	To do the analogue of ``ls -l'' one could create a function
	say ``lsl()'' along the following lines:

	lsl <- function() {
		xxx <- ls(envir=.GlobalEnv)
		yyy <- unlist(lapply(xxx,function(x){
					     a <- attr(get(x),'datestamp')
					     if(is.null(a)) NA else a
				  }
                              ))
		ooo <- order(yyy,na.last=FALSE)
		yyy[is.na(yyy)] <- "undated"
		rrr <- rep("",length(xxx))
		prmatrix(cbind(xxx[ooo],yyy[ooo]),rowlab=rrr,quote=FALSE)
		invisible()
	}
	
	The date stamping could be done by a function such as

		 stomp <- function(x){
				attr(x,'datestamp') <- paste(Sys.time())
				x
			  }

	This would work except there seems to be a bug in order()
	when na.last is set to FALSE.

	I tried

	> lsl <- stomp(lsl)
 > stomp <- stomp(stomp)
 > a <- stomp(42)
 > b <- stomp(runif(10))
 > lsl()

and got

 [,1]  [,2]               
 lsl   2005-08-12 12:38:12
 stomp 2005-08-12 12:38:27
 a     2005-08-12 12:38:35
 b     2005-08-12 12:38:46

Then I did

 > x <- 1:10 # No stomping.
 > lsl()

and got

[,1]  [,2]               
 lsl   2005-08-12 12:38:12
 stomp 2005-08-12 12:38:27
 x     undated            
 a     2005-08-12 12:38:35
 b     2005-08-12 12:38:46

so the undated x got put in the middle, rather than at the beginning
as it should've been.  Weird.  I'm going to send a separate email
about this.

				cheers,

					Rolf Turner
					rolf at math.unb.ca