<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">R vectors are passed around as immutable values, so that in theory every operation will create a new copy of the vector.<div class="">E.g., the assignment function `names&lt;-` returns a vector with a modified "names" attribute, so that "names(vect) &lt;- nams)" is equivalent to "vect &lt;- `names&lt;-`(vect, nams)".</div><div class="">Since creating new vectors all the time would be prohibitively expensive, R engines internally keep some form of "reference count" to see whether the vector is accessible from outside the current scope.</div><div class="">In the first call to `names&lt;-` in your example, the vector is only referenced by the "vect" symbol, so that it can be modified in place.</div><div class=""><br class=""></div><div class="">If you print the vector, the (internally quite complex) printing code will force the vector into a "shared" 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 class="">This call will then create a new copy of the vector with the dimensions set, but leave the original one (in "vect") unchanged.</div><div class=""><br class=""></div><div class="">Long story short, the update functions (`xyz&lt;-`) shouldn't be called directly in R, and (as Stepan said) FastR should mark all objects as "shared" when they escape the R context.</div><div class=""><br class=""></div><div class="">- Lukas</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 09.07.2018, at 15:45, Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" class="">rodrigo.a.botafogo@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="">Hello,</div><div class=""><br class=""></div><div class="">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.&nbsp; I will report it to the Gnu R user groups and see what they tell me.&nbsp; The important point here is that Graalvm is doing exactly the same as Gnu R.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Example 1:</div><div class=""><br class=""></div><div class="">&gt; vect = c(1, 2, 3, 4, 5, 6);<br class="">&gt; nams = c("a", "b", "c", "d", "e", "f");<br class="">&gt; `names&lt;-`(vect, nams);<br class="">a b c d e f<span class="Apple-converted-space">&nbsp;</span><br class="">1 2 3 4 5 6<span class="Apple-converted-space">&nbsp;</span><br class="">&gt; print(vect);<br class="">a b c d e f<span class="Apple-converted-space">&nbsp;</span><br class="">1 2 3 4 5 6<span class="Apple-converted-space">&nbsp;</span><br class="">&gt; dims = c(3, 2);<br class="">&gt; `dim&lt;-`(vect, dims);<br class="">&nbsp;&nbsp;&nbsp;&nbsp; [,1] [,2]<br class="">[1,]&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 4<br class="">[2,]&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; 5<br class="">[3,]&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; 6<br class="">&gt; print(vect);<br class="">a b c d e f<span class="Apple-converted-space">&nbsp;</span><br class="">1 2 3 4 5 6<span class="Apple-converted-space">&nbsp;</span><br class=""><br class=""></div><div class="">As we can see, the vect at the end does not have the dimension property.</div><div class=""><br class=""></div><div class="">Example 2</div><div class=""><br class=""></div><div class="">&gt; vect = c(1, 2, 3, 4, 5, 6);<br class="">&gt; nams = c("a", "b", "c", "d", "e", "f");<br class="">&gt; `names&lt;-`(vect, nams);<br class="">a b c d e f<span class="Apple-converted-space">&nbsp;</span><br class="">1 2 3 4 5 6<span class="Apple-converted-space">&nbsp;</span><br class="">&gt; # print(vect);<br class="">&gt; dims = c(3, 2);<br class="">&gt; `dim&lt;-`(vect, dims);<br class="">&nbsp;&nbsp;&nbsp;&nbsp; [,1] [,2]<br class="">[1,]&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 4<br class="">[2,]&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; 5<br class="">[3,]&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; 6<br class="">&gt; print(vect);<br class="">&nbsp;&nbsp;&nbsp;&nbsp; [,1] [,2]<br class="">[1,]&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp; 4<br class="">[2,]&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp; 5<br class="">[3,]&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp; 6<br class=""></div><div class=""><br class=""></div><div class="">In this example, the first 'print(vect)' is commented out.&nbsp; When printing vect on the last line, the dimension is set.</div><div class=""><br class=""></div></div><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;"><div dir="ltr" class="">On Fri, Jul 6, 2018 at 7:03 PM Benoit Daloze &lt;<a href="mailto:eregontp@gmail.com" target="_blank" class="">eregontp@gmail.com</a>&gt; wrote:<br class=""></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's as Stepan said.<br class="">R of course does not reassign Ruby variables.<br class="">And most R operations might or not mutate the receiver in place, with<br class="">the general model of mutating only if it's unobservable<br class="">(it is observable here, `vec` is actually a second reference to the<br class="">initial vector).<br class=""><br class="">On Fri, Jul 6, 2018 at 11:31 PM, Chris Seaton &lt;<a href="mailto:chris.seaton@oracle.com" target="_blank" class="">chris.seaton@oracle.com</a>&gt; wrote:<br class="">&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 class="">&gt;<br class="">&gt; Chris<br class="">&gt;<br class="">&gt;&gt; On 6 Jul 2018, at 17:41, Rodrigo Botafogo &lt;<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank" class="">rodrigo.a.botafogo@gmail.com</a>&gt; wrote:<br class="">&gt;&gt;<br class="">&gt;&gt; Hello,<br class="">&gt;&gt;<br class="">&gt;&gt; I'm trying to set attributes to an r object using interop.&nbsp; For some attributes everything works fine and for others the attribute is not set.<br class="">&gt;&gt;<br class="">&gt;&gt; Here what I'm trying in R:<br class="">&gt;&gt;<br class="">&gt;&gt; R.eval(&lt;&lt;-R)<br class="">&gt;&gt;&nbsp; &nbsp;vect = c(1, 2, 3, 4, 5, 6);<br class="">&gt;&gt;&nbsp; &nbsp;names(vect) = c("a", "b", "c", "d", "e", "f");<br class="">&gt;&gt;&nbsp; &nbsp;print(vect);<br class="">&gt;&gt;&nbsp; &nbsp;dim(vect) = c(3, 2);<br class="">&gt;&gt;&nbsp; &nbsp;print(vect)<br class="">&gt;&gt; R<br class="">&gt;&gt;<br class="">&gt;&gt; The first print show the names set:<br class="">&gt;&gt;<br class="">&gt;&gt; a b c d e f<br class="">&gt;&gt; 1 2 3 4 5 6<br class="">&gt;&gt;<br class="">&gt;&gt; and the second print shows the dimension change.&nbsp; Changing the "dim"<br class="">&gt;&gt; attribute erases the names attribute:<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp; [,1] [,2]<br class="">&gt;&gt; [1,]&nbsp; &nbsp; 1&nbsp; &nbsp; 4<br class="">&gt;&gt; [2,]&nbsp; &nbsp; 2&nbsp; &nbsp; 5<br class="">&gt;&gt; [3,]&nbsp; &nbsp; 3&nbsp; &nbsp; 6<br class="">&gt;&gt;<br class="">&gt;&gt; Now, doing this using interop:<br class="">&gt;&gt;<br class="">&gt;&gt; # pp to allow printing: already reported bug<br class="">&gt;&gt; pp = Polyglot.eval("R", "function(x) print(x)")<br class="">&gt;&gt;<br class="">&gt;&gt; vec = Polyglot.eval("R", "c").call(1, 2, 3, 4, 5, 6)<br class="">&gt;&gt; nams = Polyglot.eval("R", "c").call("a", "b", "c", "d", "e", "f")<br class="">&gt;&gt; Polyglot.eval("R", "`names&lt;-`").call(vec, nams)<br class="">&gt;&gt; pp.call(vec)<br class="">&gt;&gt;<br class="">&gt;&gt; this prints as expected the vector with the names attribute:<br class="">&gt;&gt;<br class="">&gt;&gt; a b c d e f<br class="">&gt;&gt; 1 2 3 4 5 6<br class="">&gt;&gt;<br class="">&gt;&gt; dims = Polyglot.eval("R", "c").call(3, 2)<br class="">&gt;&gt; Polyglot.eval("R", "`dim&lt;-`").call(vec, dims)<br class="">&gt;&gt; pp.call(vec)<br class="">&gt;&gt;<br class="">&gt;&gt; a b c d e f<br class="">&gt;&gt; 1 2 3 4 5 6<br class="">&gt;&gt;<br class="">&gt;&gt; method dim&lt;- does not seem to&nbsp; have worked.&nbsp; There is no error message or anything after calling `dim&lt;-`<br class="">&gt;&gt;<br class="">&gt;&gt; Is this a bug or did I do something wrong here?&nbsp; Its strange that some attributes work and others don't.<br class="">&gt;&gt;<br class="">&gt;&gt;<br class="">&gt;&gt;<br class="">&gt;&gt;<br class="">&gt;&gt; --<br class="">&gt;&gt; Rodrigo Botafogo<br class="">&gt;&gt;<br class="">&gt;&gt; _______________________________________________<br class="">&gt;&gt; GraalVM-Users mailing list<br class="">&gt;&gt;<span class="Apple-converted-space">&nbsp;</span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" class="">GraalVM-Users@oss.oracle.com</a><br class="">&gt;&gt;<span class="Apple-converted-space">&nbsp;</span><a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank" class="">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br class="">&gt;<br class="">&gt;<br class="">&gt; _______________________________________________<br class="">&gt; GraalVM-Users mailing list<br class="">&gt;<span class="Apple-converted-space">&nbsp;</span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" class="">GraalVM-Users@oss.oracle.com</a><br class="">&gt;<span class="Apple-converted-space">&nbsp;</span><a href="https://oss.oracle.com/mailman/listinfo/graalvm-users" rel="noreferrer" target="_blank" class="">https://oss.oracle.com/mailman/listinfo/graalvm-users</a><br class=""></blockquote></div><br clear="all" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">--<span class="Apple-converted-space">&nbsp;</span></span><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div dir="ltr" class="m_7962678476861815015gmail_signature" data-smartmail="gmail_signature" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;">Rodrigo Botafogo<br class="">Integrando TI ao seu negócio<br class="">21-3010-4802/11-3010-1802</div><span style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">GraalVM-Users mailing list</span><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">GraalVM-Users@oss.oracle.com</a><br style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://oss.oracle.com/mailman/listinfo/graalvm-users</a></div></blockquote></div><br class=""></div></body></html>