[R] Adding meta-data when creating objects. e.g: changing "<-" so to (for example) add "creation time" - how-to and pros/cons?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Nov 11 11:30:45 CET 2010


On Thu, Nov 11, 2010 at 9:37 AM, Tal Galili <tal.galili at gmail.com> wrote:

> 4) My real intention is to somehow change the "<-" operator (not simply the
> assign).  I am unsure as to how to do that.
> 5) Are there any major pros/cons to the adding of such meta-data to objects?
> (for example, excessive overhead on memory/performance)

 I had a go at doing (4) a few years back. The major problem I had was
that if you do:

 y <- 1:10
 x <- y

 with a <- operator that sets a timestamp then:

 identical(x,y) is FALSE.

I implemented timestamping by adding an attribute to objects during
assigment by modifying the C source, and then lots and lots of R's
tests failed during build because identical things were no longer
identical.

Might be better to store your metadata in a separate object, .metadata
in the global env perhaps? Then just do:

.metadata[[name_of_thing]]  = list(modified=Sys.time())

in your modified assign.

Performance will only be a problem if your program is doing nothing
else except fiddle with metadata, I reckon. Your program does do
something useful, doesn't it?

Barry



More information about the R-help mailing list