Can't call some python callables
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.8k
- Forks
- 349
- Avg merge
- 5h 13m
- Merged PRs (30d)
- 4
Description
Hi,
Should R functions converted to python still be callable from R?
library(reticulate)
fn <- r_to_py(function(x) x)
try(fn(1)) # should this succeed?
#> Error in fn(1) : could not find function "fn"
Calling py_to_r enables calling again, but doesn’t change the class or printed output.
fn
#> <function make_python_function.<locals>.python_function at 0x7f243344aef0>
class(fn)
#> [1] "python.builtin.function" "python.builtin.object"
fn <- py_to_r(fn)
fn
#> <function make_python_function.<locals>.python_function at 0x7f243344aef0>
class(fn)
#> [1] "python.builtin.function" "python.builtin.object"
fn(1)
#> 1.0
(Changing the value of convert seems to make no difference.)
This comment and the extensive use of as.environment suggests that maybe the intent is for all python callables to be callable from R and this is a bug?
It would be very convenient if all python callables are always directly callable from R without needing to go though py_call.
Created on 2021-07-02 by the reprex package (v2.0.0)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with R/python.R around the referenced line 220 and trace how r_to_py creates Python callables, including the use of as.environment. Reproduce the issue's fn(1) example and compare it with py_to_r and py_call; done means a callable returned by r_to_py can be called directly from R as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100