box icon indicating copy to clipboard operation
box copied to clipboard

Support for Positron IDE

Open GitHunter0 opened this issue 1 year ago • 3 comments

Please describe your feature request

Following discussion https://github.com/posit-dev/positron/issues/5082 , it would be very good to have box modules import working in Positron IDE.

For example, consider the case below.

We have module1.R, module2.R and __initi__.R files, all in directory C:/project/modules/, with C:/project/ being our R working directory.

# module1.R
f1 <- function(x) return(x)

Running box::use(./module1[f1]) interactively from module2.R should work.

It currently works in RStudio but still not in Positron.

GitHunter0 avatar Oct 21 '24 15:10 GitHunter0

I agree it would be really great if this would work in Positron. I love the box package and am also hoping to shift my work to Positron.

I see this issue is open, so I'm just posting here because after reading https://github.com/posit-dev/positron/issues/5082 I wasn't sure if there was some sort of work-around users could implement.

Here's a reprex from my general set up (in case it's useful):

Reproducible Example

Project Structure

reprex_box/
├── src/
│   └── func_example.R
└── scripts/
    └── test_func_example.R

src/func_example.R

#' @export
hello_box <- function(name = "World") {
  paste0("Hello from box, ", name, "!")
}

scripts/test_func_example.R (with relative import)

# This should work with box relative imports
box::use(../src/func_example)

# Test the functions
result1 <- func_example$hello_box("Positron")
print(result1)

Observed Behavior

✅ Works: Running from terminal:

From root directory:

$ Rscript scripts/test_func_example.R
#> [1] "Hello from box, Positron!"

from script directory:

$ cd scripts
$ Rscript test_func_example.R
#> [1] "Hello from box, Positron!"

❌ Fails: Running from Positron console

When running the same code in Positron console (from active script scripts/test_func_example.R) :

box::use(../src/func_example)
#> Error: unable to load module "../src/func_example"; not found in "/Users/zackarno/Downloads/reprex_box"

rstudioapi::isAvailable()
#> [1] TRUE
rstudioapi::getActiveDocumentContext()
#> Document Context: 
#> - id:        ''
#> - path:      '/Users/zackarno/Downloads/reprex_box/scripts/test_func_example.R'
#> - contents:  <23 rows>
#> Document Selection:
#> - [22, 1] -- [22, 39]: 'rstudioapi::getActiveDocumentContext() <...>'

Session info

> sessioninfo::session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.1 (2024-06-14)
 os       macOS 15.6.1
 system   aarch64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Mexico_City
 date     2025-10-06
 pandoc   NA

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date (UTC) lib source
 box           1.2.0.9000 2025-03-04 [1] [https://klmr.r-universe.dev](vscode-file://vscode-app/Applications/Positron.app/Contents/Resources/app/out/vs/code/electron-browser/workbench/workbench.html#) (R 4.4.3)
 cli           3.6.5      2025-04-23 [1] CRAN (R 4.4.1)
 fansi         1.0.6      2023-12-08 [2] CRAN (R 4.4.0)
 glue          1.8.0      2024-09-30 [1] CRAN (R 4.4.1)
 lifecycle     1.0.4      2023-11-07 [2] CRAN (R 4.4.0)
 pillar        1.9.0      2023-03-22 [2] CRAN (R 4.4.0)
 rlang         1.1.6      2025-04-11 [1] CRAN (R 4.4.1)
 sessioninfo   1.2.2      2021-12-06 [2] CRAN (R 4.4.0)
 utf8          1.2.4      2023-10-22 [2] CRAN (R 4.4.0)
 vctrs         0.6.5      2023-12-01 [2] CRAN (R 4.4.0)

 [1] /Users/zackarno/Library/R/arm64/4.4/library
 [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library

Positron Info

Positron Version: 2025.09.0 build 139
Code - OSS Version: 1.103.0
Commit: 30e3d0a74e09a0f6640929822cb57a326671360e
Date: 2025-08-29T18:31:36.739Z (1 mo ago)
Electron: 37.2.3
Chromium: 138.0.7204.100
Node.js: 22.17.0
V8: 13.8.500258-electron.0
OS: Darwin arm64 24.6.0

zackarno avatar Oct 06 '25 20:10 zackarno

@zackarno Thanks, I’ll take a look. Unfortunately the point (3) I mentioned in the linked thread is kind of an issue. in fact, I’d assume it will cause a failure when running code from inside the built-in Positron terminal. — At least this was the case when I last tested it, but that was admittedly a year ago, maybe the behaviour of Positron was fixed in the meantime.

(I’m also unable to test in Posit Workbench, and I’m somewhat queasy about this behaving differently.)

klmr avatar Oct 08 '25 13:10 klmr

I’ve re-tested this now, and scenario (3) is still returning the wrong value in up-to-date Positron. Bummer.

And I still don’t know how to handle the (fairly common) scenario where ‘rstudioapi’ isn’t installed. For now it seems that the tools:rstudio environment will always be available so I can fall back to that, but Davis’ statement that it is “not supported” is not reassuring me about its future-proofness. And this is fundamentally something that needs to be fixed in Positron. ‘box’ can only do so much.

klmr avatar Oct 11 '25 07:10 klmr