-
Notifications
You must be signed in to change notification settings - Fork 347
Description
I tried to trace py_to_r for integer conversion, but I have struggled to do so. I'm not sure whether this is something that could be implemented in reticulate, or if I should just implement some type of S3 workaround in my code.
In any case, I thought it would be desirable for reticulate to convert python integers that do not fit into 32bit integers into a 64-bit analog in R (i.e. the bit64 package). Not sure if we are waiting for R to adopt a standard here - the Python conversion is super smooth for the objects I am working with minus these IDs that get destroyed by the 32bit issue.
library(reticulate)
reticulate::py_run_string('obj = 2435823760;')
py$obj
#> [1] -1859143536
# admittedly, this does not seem to be firing
# ignorance is likely the problem
py_to_r.int <- function(x){
message('firing')
NextMethod(generic="py_to_r", object = x)
}
py$obj
#> [1] -1859143536If I were to implement a workaround, overriding with a string conversion would work fine for IDs too. It looked like int dispatch may go through py_to_r.default? Would a workaround implement a custom py_to_r.int function? I may be missing something about how this should work.