Skip to content

purpose of box:::path_tests$rstudio_path, and behavior in RStudio/Posit #394

Description

@tyner

Error description

Say I have an R script

setwd("/home/btyner/branches/r_main")
f <- box::file()
message("file is ", f)

If I run the script by manually source()ing it, f is "/home/btyner/branches/r_main". However, if I instead click the "Source" button from RStudio Desktop or Posit Workbench, f is a different directory. It seems the different behavior is due to box:::path_tests$rstudio_path (equivalently box:::rstudio_path) which makes use of the RStudio API and alters its behavior accordingly.

The difference in behavior is also observed for box::use(). In other words, this pattern

setwd("/home/btyner/branches/r_main")
box::use(./Foo/Bar[...])

will behave differently depending on the method the user chooses for sourcing.

I imagine many users believe that clicking the "Source" button is equivalent to manually running source(), since that is what is echoed on the screen upon clicking the button.

In any case, I assume the behavior observed is actually as designed, and that this is not a bug, but I am wondering what is the benefit of this? I did see some documentation under help(topic = "path", package = "box") but it doesn't really make clear that the "Source" button is special in this regard.

Thank you for considering.

R version

platform       x86_64-w64-mingw32               
arch           x86_64                           
os             mingw32                          
crt            ucrt                             
system         x86_64, mingw32                  
status                                          
major          4                                
minor          5.3                              
year           2026                             
month          03                               
day            11                               
svn rev        89597                            
language       R                                
version.string R version 4.5.3 (2026-03-11 ucrt)
nickname       Reassured Reassurer

‘box’ version

1.2.1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions