Skip to content

Dating Objects

3 messages · Rolf Turner, Barry Rowlingson, Paul Gilbert

#
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
#
Rolf Turner wrote:

            
I wanted to have some sort of 'make'-like functionality in R. Suppose 
you have some complicated analysis that depends on several variables. If 
you change one of them, you might not want to redo all the parts of the 
analyses that dont depend on that change. Integrating this with Sweave 
would be another gem, since parts of your Sweave document that might 
take a long time to run might not need to run again if you've only 
changed something after that point. If it takes an hour to generate a 
dataset and two seconds to plot it, and you've made a change to the 
plot, you dont want to re-run the whole data generation again when you 
weave your document.
A while ago I attacked this problem at the C-code level. I found out 
where R made assignments and tacked on a 'modified' attribute to the 
object at that point. However it was a quick hack and it broke R quite 
badly. One of the problems was that R objects were no longer identical 
to assigned versions of themselves, and lots of tests broke.

  I think to be done properly it needs to be done at a lower level.

Barry
#
Barry Rowlingson wrote:

            
Why not just use make and generate a sequence of targets that come from 
renaming the .RData file saved after each step.

Suppose
Well, I guess what I'm suggesting is at a much higher level.

Paul