Re: [Rd] combine UserDefinedDatabase and regular environments

From: Michael Lawrence <lawremi_at_gmail.com>
Date: Fri, 04 Dec 2009 11:12:42 -0800

On Wed, Dec 2, 2009 at 11:11 PM, Romain Francois <romain.francois_at_dbmail.com
> wrote:

> On 12/03/2009 12:17 AM, Michael Lawrence wrote:
>
>>
>>
>> On Thu, Nov 19, 2009 at 10:54 AM, Romain Francois
>> <romain.francois_at_dbmail.com <mailto:romain.francois_at_dbmail.com>> wrote:
>>
>> 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>
>> <mailto: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.
>>
>>
>>
>> Probably no clean way to accomplish that. But you could always use
>> with() if you can get that Java package as an environment.
>>
>
> Thanks for keeping this live. This would work if there was a way to
> enumerate classes from a java package, which is not always possible because
> of the flexibility of the java class loader mechanism. You can for example
> quite easily create a class loader that generates an infinity of classes ...
>
>
But wouldn't the environment be a user database and thus robust to such changes? In qtbase, class objects and instance objects are user-defined databases. R users can add methods to R extensions of C++ classes, and the instances all are kept in sync.

Romain
>
>
> Or use
>> environment<-() to enclose your function in it. That's actually fairly
>> Java-like, as normally the import has file scope and your classes are
>> enclosed within that file.
>>
>> Michael
>>
>
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
> http://romainfrancois.blog.free.fr
> |- http://tr.im/Gq7i : ohloh
> |- http://tr.im/FtUu : new package : highlight
> `- http://tr.im/EAD5 : LondonR slides
>
>

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 04 Dec 2009 - 19:17:21 GMT

This archive was generated by hypermail 2.2.0 : Sat 05 Dec 2009 - 03:31:01 GMT