fastr icon indicating copy to clipboard operation
fastr copied to clipboard

Polyglot value in R only code

Open rbotafogo opened this issue 5 years ago • 4 comments

I'm running the following code from Ruby, in RC14 ('rlang' and 'purrr') have already been loaded:

Polyglot.eval("R", <<-R)
  fidx = function(idx) {
      print(typeof(idx))
      print(class(idx))
      print(idx)
      print(is_missing(idx))
  }

  ma = missing_arg()
  f = fidx
  params = list()
  params = `[[<-`(params, 1, ma)
  invoke(f, params)

  print("======")
  fidx(ma)

R

The output of this code is:

[1] "NULL"
[1] "NULL"
[polyglot value]
[1] TRUE
[1] "======"
[1] "symbol"
[1] "name"

[1] TRUE

Note that the first time 'print(idx)' is called it outputs [polyglot value], but this should not be so, since the whole code is inside a single Polyglot call.

Also if running this code in gnuR, gives:

Error in typeof(idx) : argument "idx" is missing, with no default 

Even the call 'fidx(ma)' that does what I wanted, in gnuR actually does not work and give the same error as above.

rbotafogo avatar Mar 27 '19 15:03 rbotafogo

Hello Rodrigo,

thank you for reporting this issue. It seems that your example reveals several problems.

The printing of [polyglot value] is definitely wrong. It seems to be fixed in the master if I load purrr and then rlang, but we're getting an internal error if you load rlang and then purrr. Printing such exotic values is something we should fix, but your example reveals more important issues w.r.t. handling of missing values, which is something that's, to my knowledge, not documented anywhere and we are still trying to understand what is the intended behavior in GNU-R in such corner cases.

What is interesting is that (in GNU-R):

params = `[[<-`(params, 1, ma)

works and puts the "missing" value into the list, but if you try e.g.:

anyNA(ma)

you get the expected Error: argument "ma" is missing, with no default. From looking at GNU-R code it seems that the [[<- builtin does not check for missing values, whereas most of the other builtins do check for them. It is not clear to me if this is a bug in GNU-R or intended behavior. To better understand this, can you tell us where you got this code example from? Is it from some package/examples?

We will work on fixing this, but at this point, it seems to be something that will require more complex changes across FastR.

steve-s avatar Apr 01 '19 17:04 steve-s

Hi Stepan,

This code came from my project (Galaaz) integrating Ruby and R. In galaaz, to index a Ruby dataframe I use the symbol :all, df[idx, :all] where :all is automatically converted to 'ma' in R, which would them give df[idx, ]. But doing this was giving me the [polyglot value] message. Investigating the issue I came up with the code I´ve sent you. The information on how to get the missing value came from Advanced R by Hardley.

Em seg, 1 de abr de 2019 às 14:25, Stepan Sindelar [email protected] escreveu:

Hello Rodrigo,

thank you for reporting this issue. It seems that your example reveals several problems.

The printing of [polyglot value] is definitely wrong. It seems to be fixed in the master if I load purrr and then rlang, but we're getting an internal error if you load rlang and then purrr. Printing such exotic values is something we should fix, but your example reveals more important issues w.r.t. handling of missing values, which is something that's, to my knowledge, not documented anywhere and we are still trying to understand what is the intended behavior in GNU-R in such corner cases.

What is interesting is that (in GNU-R):

params = [[<-(params, 1, ma)

works and puts the "missing" value into the list, but if you try e.g.:

anyNA(ma)

you get the expected Error: argument "ma" is missing, with no default. From looking at GNU-R code it seems that the [[<- builtin does not check for missing values, whereas most of the other builtins do check for them. It is not clear to me if this is a bug in GNU-R or intended behavior. To better understand this, can you tell us where you got this code example from? Is it from some package/examples?

We will work on fixing this, but at this point, it seems to be something that will require more complex changes across FastR.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oracle/fastr/issues/66#issuecomment-478669846, or mute the thread https://github.com/notifications/unsubscribe-auth/AD0H8TeShX-CFf8Q1SFW7Axqo7WnbYhUks5vckEhgaJpZM4cOIen .

-- Rodrigo Botafogo

rbotafogo avatar Apr 01 '19 22:04 rbotafogo

Hello Rodrigo,

thank you for sharing the details with us. As I wrote earlier properly fixing the root cause of this is going to be complex change and will take some time. Your condensed example will be very valuable for that. For now, if you could share your concrete use case, we can take a look if we can at least get that fixed for you.

steve-s avatar Apr 04 '19 14:04 steve-s

Hi Stepan,

Thanks for the offer, but I think I can wait for the final solution... It´s not like the "millions" of users of galaaz are being very vocal about this issue!! :-)

Em qui, 4 de abr de 2019 às 11:13, Stepan Sindelar [email protected] escreveu:

Hello Rodrigo,

thank you for sharing the details with us. As I wrote earlier properly fixing the root cause of this is going to be complex change and will take some time. Your condensed example will be very valuable for that. For now, if you could share your concrete use case, we can take a look if we can at least get that fixed for you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oracle/fastr/issues/66#issuecomment-479914651, or mute the thread https://github.com/notifications/unsubscribe-auth/AD0H8RNrCwqEH_Ce3tYzdD7X2q8SZ32lks5vdgifgaJpZM4cOIen .

-- Rodrigo Botafogo

rbotafogo avatar Apr 05 '19 16:04 rbotafogo