Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support class "python.builtin.object" with "r_to_py" constructor #527

Open
moodymudskipper opened this issue Mar 14, 2025 · 0 comments
Open
Milestone

Comments

@moodymudskipper
Copy link
Collaborator

x <- reticulate::r_to_py(1:3)

# we want this:
construct(x)
#> reticulate::r_to_py(1:3)

x # x is actually an environment with a printing method
#> [1, 2, 3]    
construct(py_to_r(x)) # but we can construct the equivalent R object, so we have all we need 
#> 1:3  

General steps :

  • Define a template using .cstr_new_class("python.builtin.object", constructor = "reticulate::r_to_py", commented = TRUE) that we save in the R folder as s3-python.builtin.object.R
  • If we document, reload and retry construct(x) should already return something different.
  • Adapt .cstr_construct.python.builtin.object.r_to_py() so construct(x) returns r_to_py(1:3), look at other examples in the package, here we can use idiomatic_class = class(x) to avoid class repair
  • document and snapshot tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant