Open rbotafogo opened 5 years ago
Thanks for the report. I'll move it to FastR though, as it's their exception. It many eventually be something that Ruby is done wrong, but it should probably start with them.
Hello Rodrigo,
thank you for the report. This issue happens when the R code sends TruffleRuby object to the native code of the rlang
package. That is something we haven't encountered yet. It seems that we should allow foreign objects to leak into native code and be able to retrieve them back as results from the native code, with that implemented, I am now getting this output:
cols(
ID = col_double(),
`CONTA / INVESTIMENTO` = col_character(),
Data = col_character(),
`Quantidade Cotas` = col_double(),
`Valor Cota` = col_double(),
`Valor Nominal` = col_number(),
`Valor R$` = col_number(),
`IR + IOF` = col_logical(),
`Valor Líquido` = col_number(),
Percent = col_logical(),
Diferença = col_logical()
)
/home/steve/Development/Graal/graalvm-bin/graalvm/galaaz/lib/R_interface/rsupport.rb:235:in `exec_function': Error in mutate_impl(.data, dots) : (RuntimeError)
Evaluation error: `false` must be type integer, not double.
In addition: Warning message:
In mutate_impl(.data, dots) :
mismatched protect/unprotect (unprotect with empty protect stack) (RError)
Translated to internal error
from /home/steve/Development/Graal/graalvm-bin/graalvm-dev/galaaz/lib/R_interface/rsupport.rb:271:in `exec_function_name'
from /home/steve/Development/Graal/graalvm-bin/graalvm/galaaz/lib/R_interface/robject.rb:170:in `method_missing'
from bugs/should_not.rb:13:in `<main>'
Note that the mismatched protect/unprotect
warning is a known issue of the Rcpp
package. I assume that is still not the expected output? The error seems to be issued by galaaz
. Do you have any insight into what could be going wrong here? /CC @chrisseaton
P.S.: I reduced the set of necessary packages to dplyr
and readr
to avoid having to install whole tidyverse
Hi Stepan,
I'm not sure why a TruffleObject is being sent to rlang. Galaaz should (in principle) convert or wrap all Ruby Objects into R objects before calling any functions. So, in principle, rlang should only see R objects. But, I might have overlooked something. If a Ruby Object is being sent to R, I`d like to get an error message. I don't think that R should see leaked Ruby objects, other than by following the Truffle API, i.e., if it has a Ruby object and calls methods on them according to the API.
In the code you've executed, the expected value was the creation of a new column 'Valor BRR' with the exact same values as column 'Valor Nominal'. The expression E.if_else((:Data.eq "04/12/2018"), 1, 3.86), should be converted to the equivalent R expression => if_else((Data == "04/12/2018"), 1, 3.86). Since all elements in column 'Data' are equal to "04/12/2018", this should always evaluate to 'true' and thus the if_else should always return 1 and this multiplies the value in 'Valor Nominal'. So 'Valor BRR' = 'Valor Nominal' * 1.
Here, is a similar code that works fine. The main difference is that the data frame comes with R:
require 'galaaz'
R.install_and_loads('nycflights13')
R.library('dplyr')
@flights = ~:flights
@flights = @flights.
mutate("Diff Chegada": :arr_time - :sched_arr_time,
'Total Delay': :'Diff Chegada' *
E.if_else(((:arr_time -
:sched_arr_time) < 0), 1, 2), 'Moeda.x': "R$", 'Valor BRR': :'Diff Chegada' * E.if_else((:'Moeda.x'.eq "R$"), :'Total Delay', 100))
puts @flights.head.as__data__frame
Note that 'Valor BRR' has the same construct in here and in the example you are running. In this case if_else(Moeda.x == "R$") is always true, so it returns 'Total Delay' and 'Valor BRR' = 'Diff Chegada' * 'Total Delay'.
The output of this code is
year month day dep_time sched_dep_time dep_delay arr_time sched_arr_time 1 2013 1 1 517 515 2 830 819 2 2013 1 1 533 529 4 850 830 3 2013 1 1 542 540 2 923 850 4 2013 1 1 544 545 -1 1004 1022 5 2013 1 1 554 600 -6 812 837 6 2013 1 1 554 558 -4 740 728 arr_delay carrier flight tailnum origin dest air_time distance hour minute 1 11 UA 1545 N14228 EWR IAH 227 1400 5 15 2 20 UA 1714 N24211 LGA IAH 227 1416 5 29 3 33 AA 1141 N619AA JFK MIA 160 1089 5 40 4 -18 B6 725 N804JB JFK BQN 183 1576 5 45 5 -25 DL 461 N668DN LGA ATL 116 762 6 0 6 12 UA 1696 N39463 EWR ORD 150 719 5 58 time_hour Diff Chegada Total Delay Moeda.x Valor BRR 1 2013-01-01 05:00:00 11 22 R$ 242 2 2013-01-01 05:00:00 20 40 R$ 800 3 2013-01-01 05:00:00 73 146 R$ 10658 4 2013-01-01 05:00:00 -18 -18 R$ 324 5 2013-01-01 06:00:00 -25 -25 R$ 625 6 2013-01-01 05:00:00 12 24 R$ 288
Hope this helps!
Em sex, 3 de mai de 2019 às 09:57, Stepan Sindelar notifications@github.com escreveu:
Hello Rodrigo,
thank you for the report. This issue happens when the R code sends TruffleRuby object to the native code of the rlang package. That is something we haven't encountered yet. It seems that we should allow foreign objects to leak into native code and be able to retrieve them back as results from the native code, with that implemented, I am now getting this output:
cols(
ID = col_double(),
CONTA / INVESTIMENTO
= col_character(),Data = col_character(),
Quantidade Cotas
= col_double(),
Valor Cota
= col_double(),
Valor Nominal
= col_number(),
Valor R$
= col_number(),
IR + IOF
= col_logical(),
Valor Líquido
= col_number(),Percent = col_logical(),
Diferença = col_logical()
)
/home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/rsupport.rb:235:in `exec_function': Error in mutate_impl(.data, dots) : (RuntimeError)
Evaluation error:
false
must be type integer, not double.In addition: Warning message:
In mutate_impl(.data, dots) :
mismatched protect/unprotect (unprotect with empty protect stack) (RError)
Translated to internal error
from /home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/rsupport.rb:271:in `exec_function_name'
from /home/steve/Development/Graal/graalvm-bin/graalvm-ce-19.0.0-dev/galaaz/lib/R_interface/robject.rb:170:in `method_missing'
from bugs/should_not.rb:13:in `
' Note that the mismatched protect/unprotect warning is a known issue of the Rcpp package. I assume that is still not the expected output? The error seems to be issued by galaaz. Do you have any insight into what could be going wrong here? /CC @chrisseaton https://github.com/chrisseaton
P.S.: I reduced the set of necessary packages to dplyr and readr to avoid having to install whole tidyverse
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oracle/fastr/issues/73#issuecomment-489086206, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6QP4KY3XEASBOXRVYTHKDPTQZFHANCNFSM4HJFIOVA .
-- Rodrigo Botafogo
The following code in Galaaz get "should not reach here" message:
To reproduce: