[Rd] serialization for external pointers

Romain Francois romain at r-enthusiasts.com
Sat Nov 16 14:30:18 CET 2013


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:

$ 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
 >
 > q("yes")
get
get


romain at naxos /tmp $ R
[..]
 > fred
[1] 1
 > bindingIsActive("fred", .GlobalEnv)
[1] FALSE

Is this possible ? Is there any other hook to handle serialization, 
unserialization of external pointers ?

Romain

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



More information about the R-devel mailing list