[Rd] combine UserDefinedDatabase and regular environments

Romain Francois romain.francois at dbmail.com
Thu Nov 19 19:54:28 CET 2009


On 11/19/2009 06:14 PM, Michael Lawrence wrote:
>
>
> On Thu, Nov 5, 2009 at 9:58 AM, Romain Francois
> <romain.francois at dbmail.com <mailto:romain.francois at dbmail.com>> wrote:
>
>     Hello,
>
>     Is it possible to have the effect of UserDefinedDatabase outside of
>     "attached" environments ? Can I disguise an environment of the
>     sys.frames() as a UserDefinedDatabase ?
>
>     This seems to suggest that it might be possible :
>
>      > f <- function(){ e <- environment(); class(e) <-
>     "UserDefinedDatabase"; ff }
>      > f()
>
>
> The UserDefinedDatabase support expects an R_ObjectTable C structure
> embedded within an externalptr as the HASHTAB of the environment. So
> it's really only possible from C.

Sure. Too bad both environments and user defined database use HASHTAB 
with completely different meanings.

What I would want is something like this:

f <- function(){
	attachLocally( getSomeUserDefinedDatabaseFromC()  )
	HELLO
}

and the variable associated with the binding "HELLO" would come 
dynamically from the user defined database.


A more concrete example : rJava now has javaImport, that combined with 
attach allows dynamic lookup for class names within a set of imported 
java package paths:

attach( javaImport( "java.util" ), name = "java:java.util" )
v <- new( Vector )
m <- new( HashMap )

This is nice, but then as usual with attach, you forget to detach, ... 
this question is about to find a way to have this instead:

f <- function(){
	import( "java.util" )
	v <- new( Vector )
	v$add( 1 )
	v
}

where the "java.util" is no more looked up when f returns.


>       *** caught segfault ***
>     address (nil), cause 'unknown'
>
>     Traceback:
>       1: f()
>
>     Possible actions:
>     1: abort (with core dump, if enabled)
>     2: normal R exit
>     3: exit R without saving workspace
>     4: exit R saving workspace
>
>
>     At the moment, it seems to be either lookup using
>     UserDefinedDatabase or regular lookup. Has anyone tried to combine
>     both ?

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/EAD5 : LondonR slides
|- http://tr.im/BcPw : celebrating R commit #50000
`- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc



More information about the R-devel mailing list