[R] R GUI and object browser

Dan Putler dputler at scu.edu
Wed Jul 17 07:41:39 CEST 2002


Actually, it is fairly easy to give certain objects (those with a mode of 
"list", which includes data frames) a date attribute.  This can be done 
either after creating a list object and then providing its date attribute, or 
(in at least some instances) by modifying the function that creates that 
object to include the date attribute assignment.  The two functions needed to 
do this are the attr() and date().

Here is an example of doing this after the fact:

mydata <- data.frame(1:10,11:20)
attr(mydata, "create.date") <- date()

You can then get the value of the create.date attribute using the command

attributes(mydata)$create.date

Which will return a character string along the lines of

"Tue Jul 16 22:12:05 2002"

Moreover, my guess is that R functions that work on data frames will simply 
ignore the create.date attribute, or so my limited testing suggests.

Modifying functions that create list objects often isn't hard either (although 
I don't know if this is always the case, but suspect it is).  It turns out 
that the last two assignment statements of the data.frame() function are:

attr(value, "row.names") <- row.names
attr(value, "class") <- "data.frame"

where "value" is the internal variable name for the data frame within the 
data.frame() function.  If you modify the data.frame() function by adding the 
line

attr(value, "create.date") <- date()

after the assignment of the "class", any data frames created using this 
function will have a create.date attribute.


On Tuesday 16 July 2002 03:23 pm, Patrick Connolly wrote:
> On Mon, 15-Jul-2002 at 01:13AM -0700, Dan Putler wrote:
> |> As part of the obveRsive GUI project, we've written a function with
> |> much of the functionality that Patrick Connolly was suggesting
> |> (which is a bit more compact than the output from ls.str()).  Alas,
> |> no date capabilities.
>
> My method of getting the dates is somewhat inelegant.  However, it
> could be simple if there was a date attribute of objects.  Would such
> a thing create an overhead that could be too burdensome for people who
> don't have a use for it?  Perhaps it could be one of the general
> options that users could customize.
>
> |> The function is call ls.objects(), and example output appears below:
> |>
> |>    Object.Name Object.Mode Object.Type Observations Variables
> |> 1    ccsest.df        list  data.frame          800        21
> |> 2    ccsval.df        list  data.frame          800        21
> |> 3   junkfactor     numeric      factor          100         1
> |> 4     junklist        list     unknown            -         -
> |> 5      junkmat     numeric      matrix          100         2
> |> 6    junkmodel        list          lm            -         -
> |> 7   ls.objects    function    function            -         -
> |> 8      orderdf    function    function            -         -
> |> 9          pkg   character      vector            1         1
> |> 10       stuff        list  data.frame           12         2
> |> 11         try     numeric      vector          100         1
> |> 12        try1     numeric      vector          100         1
> |> 13        try2     numeric      vector          100         1
> |> 14      trydat        list  data.frame          100         2
> |> 15     tryname   character      vector            1         1
>
> This is certainly less complicated than my approach and does some
> things mine doesn't.
>
> best

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list