From romain at r-enthusiasts.com  Sat Nov 16 15:12:22 2013
From: romain at r-enthusiasts.com (Romain Francois)
Date: Sat, 16 Nov 2013 15:12:22 +0100
Subject: [Rd] serialization for external pointers
In-Reply-To: <5287736A.6000407@r-enthusiasts.com>
References: <5287736A.6000407@r-enthusiasts.com>
Message-ID: <52877D46.5090202@r-enthusiasts.com>

Le 16/11/2013 14:30, Romain Francois a ?crit :
> Hello,
>
> Are there any recipe to handle serialization / deserialization of
> external pointers.
>
> I'm thinking about something similar in spirit to the way we handle
> finalization of external pointers.
>
> Currently, if we create an external pointer, save the session, quit R,
> then load the session, we get a null pointer.
>
> One way I'm thinking of is to have an environment in the "protected"
> part of the xp, then have an active binding there, since apparently
> active bindings:
>   - are "get" during serialization
>   - lose their active ness when reloaded:

This will not work. Apparently the active feature is kept on other 
environments:

$ R
[...]
 > f <- local( {
+     x <- 1
+     function(v) {
+        if (missing(v))
+            cat("get\n")
+        else {
+            cat("set\n")
+            x <<- v
+        }
+        x
+     }
+ })
 > makeActiveBinding("fred", f, .GlobalEnv)
 > bindingIsActive("fred", .GlobalEnv)
[1] TRUE
 >
 > e <- new.env()
 > makeActiveBinding("fred", f, e)
 > bindingIsActive("fred", e)
[1] TRUE
 >
 > q()
Save workspace image? [y/n/c]: y
get
get

Then:

$ R
[...]
 > e
<environment: 0x104c56f78>
 > bindingIsActive("fred", .GlobalEnv)
[1] FALSE
 > bindingIsActive("fred", e)
[1] TRUE

Is this the expected behavior ?

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30



[Rd] serialization for external pointers
Romain Francois