<div dir="ltr"><div>Lukas,</div><div><br></div><div><br></div><div>Thanks a lot for the explanation... things are now clear!</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jul 9, 2018 at 1:01 PM Lukas Stadler &lt;<a href="mailto:lukas.stadler@oracle.com">lukas.stadler@oracle.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">R vectors are passed around as immutable values, so that in theory every operation will create a new copy of the vector.<div>E.g., the assignment function `names&lt;-` returns a vector with a modified &quot;names&quot; attribute, so that &quot;names(vect) &lt;- nams)&quot; is equivalent to &quot;vect &lt;- `names&lt;-`(vect, nams)&quot;.</div><div>Since creating new vectors all the time would be prohibitively expensive, R engines internally keep some form of &quot;reference count&quot; to see whether the vector is accessible from outside the current scope.</div><div>In the first call to `names&lt;-` in your example, the vector is only referenced by the &quot;vect&quot; symbol, so that it can be modified in place.</div><div><br></div><div>If you print the vector, the (internally quite complex) printing code will force the vector into a &quot;shared&quot; state, which requires a copy-on-write the next time it is modified, which in your case is the call to `dim&lt;-`.</div><div>This call will then create a new copy of the vector with the dimensions set, but leave the original one (in &quot;vect&quot;) unchanged.</div><div><br></div><div>Long story short, the update functions (`xyz&lt;-`) shouldn&#39;t be called directly in R, and (as Stepan said) FastR should mark all objects as &quot;shared&quot; when they escape the R context.</div><div><br></div><div>- Lukas</div><div><div><br><blockquote type="cite"><div>On 09.07.2018, at 15:45, Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>&gt; wrote:</div><br class="m_2324912071154751159Apple-interchange-newline"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><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&#39;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 &#39;print&#39; on the second code:</div><div><br></div><div>Example 1:</div><div><br></div><div>&gt; vect = c(1, 2, 3, 4, 5, 6);<br>&gt; nams = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;);<br>&gt; `names&lt;-`(vect, nams);<br>a b c d e f<span class="m_2324912071154751159Apple-converted-space"> </span><br>1 2 3 4 5 6<span class="m_2324912071154751159Apple-converted-space"> </span><br>&gt; print(vect);<br>a b c d e f<span class="m_2324912071154751159Apple-converted-space"> </span><br>1 2 3 4 5 6<span class="m_2324912071154751159Apple-converted-space"> </span><br>&gt; dims = c(3, 2);<br>&gt; `dim&lt;-`(vect, dims);<br>     [,1] [,2]<br>[1,]    1    4<br>[2,]    2    5<br>[3,]    3    6<br>&gt; print(vect);<br>a b c d e f<span class="m_2324912071154751159Apple-converted-space"> </span><br>1 2 3 4 5 6<span class="m_2324912071154751159Apple-converted-space"> </span><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>&gt; vect = c(1, 2, 3, 4, 5, 6);<br>&gt; nams = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;);<br>&gt; `names&lt;-`(vect, nams);<br>a b c d e f<span class="m_2324912071154751159Apple-converted-space"> </span><br>1 2 3 4 5 6<span class="m_2324912071154751159Apple-converted-space"> </span><br>&gt; # print(vect);<br>&gt; dims = c(3, 2);<br>&gt; `dim&lt;-`(vect, dims);<br>     [,1] [,2]<br>[1,]    1    4<br>[2,]    2    5<br>[3,]    3    6<br>&gt; 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 &#39;print(vect)&#39; is commented out.  When printing vect on the last line, the dimension is set.</div><div><br></div></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr">On Fri, Jul 6, 2018 at 7:03 PM Benoit Daloze &lt;<a href="mailto:eregontp@gmail.com" target="_blank">eregontp@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">It seems to me it&#39;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&#39;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 &lt;<a href="mailto:chris.seaton@oracle.com" target="_blank">chris.seaton@oracle.com</a>&gt; wrote:<br>&gt; Maybe this is something to do with the `dim&lt;-` 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>&gt;<br>&gt; Chris<br>&gt;<br>&gt;&gt; On 6 Jul 2018, at 17:41, Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank">rodrigo.a.botafogo@gmail.com</a>&gt; wrote:<br>&gt;&gt;<br>&gt;&gt; Hello,<br>&gt;&gt;<br>&gt;&gt; I&#39;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>&gt;&gt;<br>&gt;&gt; Here what I&#39;m trying in R:<br>&gt;&gt;<br>&gt;&gt; R.eval(&lt;&lt;-R)<br>&gt;&gt;   vect = c(1, 2, 3, 4, 5, 6);<br>&gt;&gt;   names(vect) = c(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;);<br>&gt;&gt;   print(vect);<br>&gt;&gt;   dim(vect) = c(3, 2);<br>&gt;&gt;   print(vect)<br>&gt;&gt; R<br>&gt;&gt;<br>&gt;&gt; The first print show the names set:<br>&gt;&gt;<br>&gt;&gt; a b c d e f<br>&gt;&gt; 1 2 3 4 5 6<br>&gt;&gt;<br>&gt;&gt; and the second print shows the dimension change.  Changing the &quot;dim&quot;<br>&gt;&gt; attribute erases the names attribute:<br>&gt;&gt;      [,1] [,2]<br>&gt;&gt; [1,]    1    4<br>&gt;&gt; [2,]    2    5<br>&gt;&gt; [3,]    3    6<br>&gt;&gt;<br>&gt;&gt; Now, doing this using interop:<br>&gt;&gt;<br>&gt;&gt; # pp to allow printing: already reported bug<br>&gt;&gt; pp = Polyglot.eval(&quot;R&quot;, &quot;function(x) print(x)&quot;)<br>&gt;&gt;<br>&gt;&gt; vec = Polyglot.eval(&quot;R&quot;, &quot;c&quot;).call(1, 2, 3, 4, 5, 6)<br>&gt;&gt; nams = Polyglot.eval(&quot;R&quot;, &quot;c&quot;).call(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;)<br>&gt;&gt; Polyglot.eval(&quot;R&quot;, &quot;`names&lt;-`&quot;).call(vec, nams)<br>&gt;&gt; pp.call(vec)<br>&gt;&gt;<br>&gt;&gt; this prints as expected the vector with the names attribute:<br>&gt;&gt;<br>&gt;&gt; a b c d e f<br>&gt;&gt; 1 2 3 4 5 6<br>&gt;&gt;<br>&gt;&gt; dims = Polyglot.eval(&quot;R&quot;, &quot;c&quot;).call(3, 2)<br>&gt;&gt; Polyglot.eval(&quot;R&quot;, &quot;`dim&lt;-`&quot;).call(vec, dims)<br>&gt;&gt; pp.call(vec)<br>&gt;&gt;<br>&gt;&gt; a b c d e f<br>&gt;&gt; 1 2 3 4 5 6<br>&gt;&gt;<br>&gt;&gt; method dim&lt;- does not seem to  have worked.  There is no error message or anything after calling `dim&lt;-`<br>&gt;&gt;<br>&gt;&gt; Is this a bug or did I do something wrong here?  Its strange that some attributes work and others don&#39;t.<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; --<br>&gt;&gt; Rodrigo Botafogo<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>&gt;&gt; GraalVM-Users mailing list<br>&gt;&gt;<span class="m_2324912071154751159Apple-converted-space"> </span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>&gt;&gt;<span class="m_2324912071154751159Apple-converted-space"> </span><a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; GraalVM-Users mailing list<br>&gt;<span class="m_2324912071154751159Apple-converted-space"> </span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank">GraalVM-Users@oss.oracle.com</a><br>&gt;<span class="m_2324912071154751159Apple-converted-space"> </span><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" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">--<span class="m_2324912071154751159Apple-converted-space"> </span></span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div dir="ltr" class="m_2324912071154751159m_7962678476861815015gmail_signature" data-smartmail="gmail_signature" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">Rodrigo Botafogo<br>Integrando TI ao seu negócio<br>21-3010-4802/11-3010-1802</div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline!important">GraalVM-Users mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="mailto:GraalVM-Users@oss.oracle.com" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">GraalVM-Users@oss.oracle.com</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></div></blockquote></div><br></div></div></blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Rodrigo Botafogo<br>Integrando TI ao seu negócio<br>21-3010-4802/11-3010-1802</div>