[graalvm-users] Setting attributes inconsistencies

Stepan stepan.sindelar at oracle.com
Fri Jul 6 14:30:36 PDT 2018


Hi Rodrigo,

you need to assign the result of the call to the variable like so

vec = Polyglot.eval("R", "`dim<-`").call(vec, dims)

"XYZ<-" functions return the resulting object. For performance reasons, 
they may update the first parameter in-place if there is at most one 
reference to it, but it is always safer to use the return value.

Best,
Stepan

On 06/07/18 18:41, Rodrigo Botafogo wrote:
> Hello,
> 
> I'm trying to set attributes to an r object using interop.  For some 
> attributes everything works fine and for others the attribute is not set.
> 
> Here what I'm trying in R:
> 
> R.eval(<<-R)
>    vect = c(1, 2, 3, 4, 5, 6);
>    names(vect) = c("a", "b", "c", "d", "e", "f");
>    print(vect);
>    dim(vect) = c(3, 2);
>    print(vect)
> R
> 
> The first print show the names set:
> 
> a b c d e f
> 1 2 3 4 5 6
> 
> and the second print shows the dimension change.  Changing the "dim"
> attribute erases the names attribute:
>       [,1] [,2]
> [1,]    1    4
> [2,]    2    5
> [3,]    3    6
> 
> Now, doing this using interop:
> 
> # pp to allow printing: already reported bug
> pp = Polyglot.eval("R", "function(x) print(x)")
> 
> vec = Polyglot.eval("R", "c").call(1, 2, 3, 4, 5, 6)
> nams = Polyglot.eval("R", "c").call("a", "b", "c", "d", "e", "f")
> Polyglot.eval("R", "`names<-`").call(vec, nams)
> pp.call(vec)
> 
> this prints as expected the vector with the names attribute:
> 
> a b c d e f
> 1 2 3 4 5 6
> 
> dims = Polyglot.eval("R", "c").call(3, 2)
> Polyglot.eval("R", "`dim<-`").call(vec, dims)
> pp.call(vec)
> 
> a b c d e f
> 1 2 3 4 5 6
> 
> method dim<- does not seem to  have worked.  There is no error message 
> or anything after calling `dim<-`
> 
> Is this a bug or did I do something wrong here?  Its strange that some 
> attributes work and others don't.
> 
> 
> 
> 
> -- 
> Rodrigo Botafogo
> 
> 
> 
> _______________________________________________
> GraalVM-Users mailing list
> GraalVM-Users at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/graalvm-users
> 



More information about the GraalVM-Users mailing list