[graalvm-users] Setting attributes inconsistencies

Benoit Daloze eregontp at gmail.com
Fri Jul 6 15:03:07 PDT 2018


It seems to me it's as Stepan said.
R of course does not reassign Ruby variables.
And most R operations might or not mutate the receiver in place, with
the general model of mutating only if it's unobservable
(it is observable here, `vec` is actually a second reference to the
initial vector).

On Fri, Jul 6, 2018 at 11:31 PM, Chris Seaton <chris.seaton at oracle.com> wrote:
> Maybe this is something to do with the `dim<-` method? I don’t know anything about R but I guess that’s called when you do `names(something) =`. Can you try making a simple test case that just tests that these kind of methods can be called correctly? Maybe something about it messes up the arguments?
>
> Chris
>
>> On 6 Jul 2018, at 17:41, Rodrigo Botafogo <rodrigo.a.botafogo at gmail.com> 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
>
>
> _______________________________________________
> 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