posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.83k stars 91 forks source link

No passing R and Python object within reticulate session in Positron #5210

Open ntluong95 opened 3 weeks ago

ntluong95 commented 3 weeks ago

System details:

Positron and OS details:

Positron Version: 2024.11.0 (system setup) build 116 Code - OSS Version: 1.93.0 Commit: 8b1688ababfa228db515a739050c466f3bb3089f Date: 2024-10-28T02:47:45.218Z Electron: 30.4.0 Chromium: 124.0.6367.243 Node.js: 20.15.1 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.22621

Interpreter details:

R 4.3.2 Python 3.12.4

Describe the issue:

It is unable to access R object through r.object syntax and python object through py$object syntax in Positron

Steps to reproduce the issue:

  1. Create a new quarto document
  2. Create a venv through uv package or whatever way
uv init --python 3.12.4
uv add ipykernel
uv add pyarrow
  1. Run the following code
library(arrow)
library(reticulate)
use_virtualenv(here::here(".venv"))
repl_python()
import pyarrow as pa
set.seed(1234)
nrows <- 10^4
df_random <- data.frame(
  x = rnorm(nrows), 
  y = rnorm(nrows),
  subset = sample(10, nrows, replace = TRUE)
)
tb_random <- arrow_table(df_random)

df_py <- r_to_py(df_random)
tb_py <- r_to_py(tb_random)
r.df_py

r.tb_py 

Expected or desired behavior:

Be able to access the dataframe

Were there any error messages in the UI, Output panel, or Developer Tools console?

Actual output Image

The object was converted and showed in Environment Pane Image

Image

dfalbel commented 3 weeks ago

Thank you for reporting!

This should have been fixed with https://github.com/rstudio/reticulate/pull/1681 Can you try installing the dev version of reticulate and see if the issue persists?

ntluong95 commented 3 weeks ago

I have tried and confirmed that it solved the problem. But I don't know why sometimes I can import pyarrow, sometimes I can't. Not sure if anything need to be done with reticulate or python

Image

juliasilge commented 3 weeks ago

@dfalbel Should Positron check for the reticulate R package version? We do this in the R extension like so:

https://github.com/posit-dev/positron/blob/1cda237653eaad30a3edc45ff47d90bfa3fac24e/extensions/positron-r/src/commands.ts#L193

dfalbel commented 3 weeks ago

We do check for a minimum reticulate version here:

https://github.com/posit-dev/positron/blob/3e71716fa4a6ed5e051c835851571f3ff312d73f/extensions/positron-reticulate/src/extension.ts#L220-L221

But still didn't bump it up to fix this specific bug because the new release is not on CRAN yet.