Re: [R] Dating Objects

From: David Whiting <david.whiting_at_ncl.ac.uk>
Date: Sat 13 Aug 2005 - 01:48:18 EST

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)

______________________________________________
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 01:52:58 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:17:13 EST