Hi I know this subject has been mentioned before but from the mail archives I'm under the impression that this is not possible ? 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. Or am I just wasting my time ? Apologies but my knowledge of R is limited at best ;-( Any help would be fantastic and greatfully received Cheers Jason -- -------------------------------- Jason Skelton Pathogen Microarrays Wellcome Trust Sanger Institute Hinxton Cambridge CB10 1SA Tel +44(0)1223 834244 Ext 7123 Fax +44(0)1223 494919
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... ---------------------------------------------------------- SIGSIG -- signature too long (core dumped)
Hi Jason, Perhaps you get do what you want to do using attributes? Does this get close to what you need?> ## Create some objects > xx <- "adsfasdf" > zz <- 3027 > yy <- "abdsf" > > ## Assign a time attribute to them. > attr(zz, "time") <- Sys.time() > attr(yy, "time") <- Sys.time() > > ## To see the time attribute of, for example, zz: > attributes(zz)$time[1] "2005-08-12 16:46:47 BST"> > ## A crude function to show the time attributes > ## of objects: > > time.attr <- function (x) {+ x.attr <- attributes(get(x)) + attr.names <- names(attributes(get(x))) + if (!is.null(attr.names) && attr.names %in% "time") { + x.time <- x.attr$time + names(x.time) <- x + x.time + } + }> > ## Apply the time.attr function to all objects listed by ls(): > lapply(ls(), time.attr)[[1]] NULL [[2]] NULL [[3]] yy "2005-08-12 16:46:47 BST" [[4]] zz "2005-08-12 16:46:47 BST" Dave Jason Skelton wrote:> Hi > > I know this subject has been mentioned before but from the mail archives > I'm under the impression that this is not possible ? > 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. > Or am I just wasting my time ? > > Apologies but my knowledge of R is limited at best ;-( > Any help would be fantastic and greatfully received > > Cheers > > Jason > > >-- David Whiting School of Clinical Medical Sciences, The Medical School University of Newcastle upon Tyne, NE2 4HH, UK. "I love deadlines. I love the whooshing noise they make as they go by" (Douglas Adams)
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 at math.unb.ca