Re: [R] Dating Objects

From: Rolf Turner <rolf_at_math.unb.ca>
Date: Sat 13 Aug 2005 - 01:56:14 EST


Paul Roebuck wrote:

On Fri, 12 Aug 2005, Jason Skelton wrote:

> > I'm trying to carryout the equivalent of ls -l in R
> > to give some date/time label to each of my objects
> >
> > If the case is that there is no equivalent, is it
> > possible to list all objects in an environment that
> > share a common component so that the common component
> > is also displayed?
> >
> > I'm attempting to do the following
> >
> > object$time <- Sys.time()
> >
> > for every object i've created which although tedious
> > appears to work
> >
> > However I've no idea how if it is possible to list all
> > the objects by $time or extract the object name & $time
> > from all objects simultaneously so I can compare them.
>
> Not really following why you want to do this so it's
> hard to suggest something. Were you attempting to track
> mtime or ctime?
>
> Perhaps instead you could describe the larger problem
> you're trying to solve so there's more context to work
> with.
>
> > Or am I just wasting my time?
>
> Most of us probably are...

	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@math.unb.ca

______________________________________________
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 Sat Aug 13 02:04:09 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:47 EST