Skip to content
Prev 27769 / 63424 Next

how to write dput-able objects

Try something like this.  If ..Name exists in the proto object
it uses that as the name; otherwise, it uses the name.proto()
heuristic to find the name.

library(proto)
dput.proto <- function(x, ...) {
    y <- as.list(x, all = TRUE)
    if (!exists("..Name", x)) y$..Name <- name.proto(x, parent.frame())
    y$.parent.Name <- name.proto(parent.env(x), parent.frame())
    dput(y, ...)
}
p <- proto(a = 1, f = function(.) { .$a <- .$a + 1})
q <- p$proto(a = 2)
dput.proto(p)
dput.proto(q)

Output:
structure(list(.super = <environment>, .that = <environment>,
    a = 1, f = function (.)
    {
        .$a <- .$a + 1
    }, ..Name = "p", .parent.Name = "R_GlobalEnv"), .Names = c(".super",
".that", "a", "f", "..Name", ".parent.Name"))
structure(list(.super = <environment>, .that = <environment>,
    a = 2, ..Name = "q", .parent.Name = "p"), .Names = c(".super",
".that", "a", "..Name", ".parent.Name"))



On Mon, Feb 25, 2008 at 2:17 PM, Vadim Organovich
<vogranovich at jumptrading.com> wrote: