[graalvm-users] Setting attributes inconsistencies

Rodrigo Botafogo rodrigo.a.botafogo at gmail.com
Mon Jul 9 06:45:19 PDT 2018


Hello,

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.

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:

Example 1:

> vect = c(1, 2, 3, 4, 5, 6);
> nams = c("a", "b", "c", "d", "e", "f");
> `names<-`(vect, nams);
a b c d e f
1 2 3 4 5 6
> print(vect);
a b c d e f
1 2 3 4 5 6
> dims = c(3, 2);
> `dim<-`(vect, dims);
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
> print(vect);
a b c d e f
1 2 3 4 5 6

As we can see, the vect at the end does not have the dimension property.

Example 2

> vect = c(1, 2, 3, 4, 5, 6);
> nams = c("a", "b", "c", "d", "e", "f");
> `names<-`(vect, nams);
a b c d e f
1 2 3 4 5 6
> # print(vect);
> dims = c(3, 2);
> `dim<-`(vect, dims);
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6
> print(vect);
     [,1] [,2]
[1,]    1    4
[2,]    2    5
[3,]    3    6

In this example, the first 'print(vect)' is commented out.  When printing
vect on the last line, the dimension is set.


On Fri, Jul 6, 2018 at 7:03 PM Benoit Daloze <eregontp at gmail.com> wrote:

> 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
>


-- 
Rodrigo Botafogo
Integrando TI ao seu negócio
21-3010-4802/11-3010-1802
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20180709/a73ed540/attachment.html 


More information about the GraalVM-Users mailing list