<div dir="ltr"><div>Hello,</div><div><br></div><div>Thanks for all the answers. It just did a bunch of test and it seems to me now to either be a bug in Gnu R or just a very strange behavior that I don't understand either about R. I will report it to the Gnu R user groups and see what they tell me. The important point here is that Graalvm is doing exactly the same as Gnu R.</div><div><br></div><div>For the curious, here what happens in GNU R. Bellow, two examples. The only difference between the two is that I commented a 'print' on the second code:</div><div><br></div><div>Example 1:</div><div><br></div><div>> vect = c(1, 2, 3, 4, 5, 6);<br>> nams = c("a", "b", "c", "d", "e", "f");<br>> `names<-`(vect, nams);<br>a b c d e f <br>1 2 3 4 5 6 <br>> print(vect);<br>a b c d e f <br>1 2 3 4 5 6 <br>> dims = c(3, 2);<br>> `dim<-`(vect, dims);<br> [,1] [,2]<br>[1,] 1 4<br>[2,] 2 5<br>[3,] 3 6<br>> print(vect);<br>a b c d e f <br>1 2 3 4 5 6 <br><br></div><div>As we can see, the vect at the end does not have the dimension property.</div><div><br></div><div>Example 2</div><div><br></div><div>> vect = c(1, 2, 3, 4, 5, 6);<br>> nams = c("a", "b", "c", "d", "e", "f");<br>> `names<-`(vect, nams);<br>a b c d e f <br>1 2 3 4 5 6 <br>> # print(vect);<br>> dims = c(3, 2);<br>> `dim<-`(vect, dims);<br> [,1] [,2]<br>[1,] 1 4<br>[2,] 2 5<br>[3,] 3 6<br>> print(vect);<br> [,1] [,2]<br>[1,] 1 4<br>[2,] 2 5<br>[3,] 3 6<br></div><div><br></div><div>In this example, the first 'print(vect)' is commented out. When printing vect on the last line, the dimension is set.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 6, 2018 at 7:03 PM Benoit Daloze <<a href="mailto:eregontp@gmail.com" target="_blank">eregontp@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It seems to me it's as Stepan said.<br>
R of course does not reassign Ruby variables.<br>
And most R operations might or not mutate the receiver in place, with<br>
the general model of mutating only if it's unobservable<br>
(it is observable here, `vec` is actually a second reference to the<br>
initial vector).<br>
<br>
On Fri, Jul 6, 2018 at 11:31 PM, Chris Seaton <<a href="mailto:chris.seaton@oracle.com" target="_blank">chris.seaton@oracle.com</a>> wrote:<br>
> 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?<br>
><br>
> Chris<br>
><br>
>> On 6 Jul 2018, at 17:41, Rodrigo Botafogo <<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>> wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> 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.<br>
>><br>
>> Here what I'm trying in R:<br>
>><br>
>> R.eval(<<-R)<br>
>> vect = c(1, 2, 3, 4, 5, 6);<br>
>> names(vect) = c("a", "b", "c", "d", "e", "f");<br>
>> print(vect);<br>
>> dim(vect) = c(3, 2);<br>
>> print(vect)<br>
>> R<br>
>><br>
>> The first print show the names set:<br>
>><br>
>> a b c d e f<br>
>> 1 2 3 4 5 6<br>
>><br>
>> and the second print shows the dimension change. Changing the "dim"<br>
>> attribute erases the names attribute:<br>
>> [,1] [,2]<br>
>> [1,] 1 4<br>
>> [2,] 2 5<br>
>> [3,] 3 6<br>
>><br>
>> Now, doing this using interop:<br>
>><br>
>> # pp to allow printing: already reported bug<br>
>> pp = Polyglot.eval("R", "function(x) print(x)")<br>
>><br>
>> vec = Polyglot.eval("R", "c").call(1, 2, 3, 4, 5, 6)<br>
>> nams = Polyglot.eval("R", "c").call("a", "b", "c", "d", "e", "f")<br>
>> Polyglot.eval("R", "`names<-`").call(vec, nams)<br>
>> pp.call(vec)<br>
>><br>
>> this prints as expected the vector with the names attribute:<br>
>><br>
>> a b c d e f<br>
>> 1 2 3 4 5 6<br>
>><br>
>> dims = Polyglot.eval("R", "c").call(3, 2)<br>
>> Polyglot.eval("R", "`dim<-`").call(vec, dims)<br>
>> pp.call(vec)<br>
>><br>
>> a b c d e f<br>
>> 1 2 3 4 5 6<br>
>><br>
>> method dim<- does not seem to have worked. There is no error message or anything after calling `dim<-`<br>
>><br>
>> Is this a bug or did I do something wrong here? Its strange that some attributes work and others don't.<br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>> Rodrigo Botafogo<br>
>><br>
>> _______________________________________________<br>
>> GraalVM-Users mailing list<br>
>> <a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>
>> <a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>
><br>
><br>
> _______________________________________________<br>
> GraalVM-Users mailing list<br>
> <a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>
> <a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="m_7962678476861815015gmail_signature" data-smartmail="gmail_signature">Rodrigo Botafogo<br>Integrando TI ao seu negócio<br>21-3010-4802/11-3010-1802</div>