<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<-` returns a vector with a modified "names" attribute, so that "names(vect) <- nams)" is equivalent to "vect <- `names<-`(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<-` 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<-`.</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<-`) 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 <<a href="mailto:rodrigo.a.botafogo@gmail.com" class="">rodrigo.a.botafogo@gmail.com</a>> 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. 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 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="">> vect = c(1, 2, 3, 4, 5, 6);<br class="">> nams = c("a", "b", "c", "d", "e", "f");<br class="">> `names<-`(vect, nams);<br class="">a b c d e f<span class="Apple-converted-space"> </span><br class="">1 2 3 4 5 6<span class="Apple-converted-space"> </span><br class="">> print(vect);<br class="">a b c d e f<span class="Apple-converted-space"> </span><br class="">1 2 3 4 5 6<span class="Apple-converted-space"> </span><br class="">> dims = c(3, 2);<br class="">> `dim<-`(vect, dims);<br class=""> [,1] [,2]<br class="">[1,] 1 4<br class="">[2,] 2 5<br class="">[3,] 3 6<br class="">> print(vect);<br class="">a b c d e f<span class="Apple-converted-space"> </span><br class="">1 2 3 4 5 6<span class="Apple-converted-space"> </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="">> vect = c(1, 2, 3, 4, 5, 6);<br class="">> nams = c("a", "b", "c", "d", "e", "f");<br class="">> `names<-`(vect, nams);<br class="">a b c d e f<span class="Apple-converted-space"> </span><br class="">1 2 3 4 5 6<span class="Apple-converted-space"> </span><br class="">> # print(vect);<br class="">> dims = c(3, 2);<br class="">> `dim<-`(vect, dims);<br class=""> [,1] [,2]<br class="">[1,] 1 4<br class="">[2,] 2 5<br class="">[3,] 3 6<br class="">> print(vect);<br class=""> [,1] [,2]<br class="">[1,] 1 4<br class="">[2,] 2 5<br class="">[3,] 3 6<br class=""></div><div class=""><br class=""></div><div class="">In this example, the first 'print(vect)' is commented out. 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 <<a href="mailto:eregontp@gmail.com" target="_blank" class="">eregontp@gmail.com</a>> 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 <<a href="mailto:chris.seaton@oracle.com" target="_blank" class="">chris.seaton@oracle.com</a>> wrote:<br class="">> 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 class="">><br class="">> Chris<br class="">><br class="">>> On 6 Jul 2018, at 17:41, Rodrigo Botafogo <<a href="mailto:rodrigo.a.botafogo@gmail.com" target="_blank" class="">rodrigo.a.botafogo@gmail.com</a>> wrote:<br class="">>><br class="">>> Hello,<br class="">>><br class="">>> 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 class="">>><br class="">>> Here what I'm trying in R:<br class="">>><br class="">>> R.eval(<<-R)<br class="">>> vect = c(1, 2, 3, 4, 5, 6);<br class="">>> names(vect) = c("a", "b", "c", "d", "e", "f");<br class="">>> print(vect);<br class="">>> dim(vect) = c(3, 2);<br class="">>> print(vect)<br class="">>> R<br class="">>><br class="">>> The first print show the names set:<br class="">>><br class="">>> a b c d e f<br class="">>> 1 2 3 4 5 6<br class="">>><br class="">>> and the second print shows the dimension change. Changing the "dim"<br class="">>> attribute erases the names attribute:<br class="">>> [,1] [,2]<br class="">>> [1,] 1 4<br class="">>> [2,] 2 5<br class="">>> [3,] 3 6<br class="">>><br class="">>> Now, doing this using interop:<br class="">>><br class="">>> # pp to allow printing: already reported bug<br class="">>> pp = Polyglot.eval("R", "function(x) print(x)")<br class="">>><br class="">>> vec = Polyglot.eval("R", "c").call(1, 2, 3, 4, 5, 6)<br class="">>> nams = Polyglot.eval("R", "c").call("a", "b", "c", "d", "e", "f")<br class="">>> Polyglot.eval("R", "`names<-`").call(vec, nams)<br class="">>> pp.call(vec)<br class="">>><br class="">>> this prints as expected the vector with the names attribute:<br class="">>><br class="">>> a b c d e f<br class="">>> 1 2 3 4 5 6<br class="">>><br class="">>> dims = Polyglot.eval("R", "c").call(3, 2)<br class="">>> Polyglot.eval("R", "`dim<-`").call(vec, dims)<br class="">>> pp.call(vec)<br class="">>><br class="">>> a b c d e f<br class="">>> 1 2 3 4 5 6<br class="">>><br class="">>> method dim<- does not seem to have worked. There is no error message or anything after calling `dim<-`<br class="">>><br class="">>> Is this a bug or did I do something wrong here? Its strange that some attributes work and others don't.<br class="">>><br class="">>><br class="">>><br class="">>><br class="">>> --<br class="">>> Rodrigo Botafogo<br class="">>><br class="">>> _______________________________________________<br class="">>> GraalVM-Users mailing list<br class="">>><span class="Apple-converted-space"> </span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" class="">GraalVM-Users@oss.oracle.com</a><br class="">>><span class="Apple-converted-space"> </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="">><br class="">><br class="">> _______________________________________________<br class="">> GraalVM-Users mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:GraalVM-Users@oss.oracle.com" target="_blank" class="">GraalVM-Users@oss.oracle.com</a><br class="">><span class="Apple-converted-space"> </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"> </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>