Relative paths based on Rproj
like here::here
?
#328
-
I have a project structured as such:
Sometimes I work from my main project open in I tried to understand how relative paths work for box:
I want to be able to write code in my projects and sub projects and not have to modify the paths based on which project I have open in a window. # now from main_project I have to do this
box::use(./utilities/some_R6_module[ R6_class ])
# but from a sub-project I have to do this
box::use(../utilities/some_R6_module[ R6_class ])
# here solves this by keeping the root relative to where the rproj is
here::here(".") # always returns main_project as root
box::file() # returns the top level of the current window open in vscode Can I use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I’m trying to understand the problem you are experiencing but unfortunately I am having trouble with that. From your description, everything seems to work as expected. I think the issue boils down to a mismatch in the mental model — and please correct me if I am wrong. Here’s what I think the situation is: you have an R project with several submodules, and you treat that project as a single unit. By contrast, ‘box’ has no concept of projects, only of modules. That’s because R itself does not have a concept of projects. RStudio does, but not everybody is using RStudio, and RStudio projects are not suite for all types of R code. As a direct consequence of that, ‘box’ resolves all paths relative to the current (= calling) module. This behaviour is consistent across So if you want to use module import declarations relative to the project root I’m afraid you can’t, since there’s no such thing as a “project root” in R. ‘here’ uses error-prone heuristics to detect the project root1 and ‘box’ intentionally does not rely on it. Think of (sub)modules as packages, not as projects. Inside a package in R you cannot call The correct, intended way of loading related modules is therefore via relative paths, indicated by the prefixes To answer your concrete questions:
1 To illustrate why, |
Beta Was this translation helpful? Give feedback.
I’m trying to understand the problem you are experiencing but unfortunately I am having trouble with that. From your description, everything seems to work as expected.
I think the issue boils down to a mismatch in the mental model — and please correct me if I am wrong. Here’s what I think the situation is: you have an R project with several submodules, and you treat that project as a single unit. By contrast, ‘box’ has no concept of projects, only of modules. That’s because R itself does not have a concept of projects. RStudio does, but not everybody is using RStudio, and RStudio projects are not suite for all types of R code.
As a direct consequence of that, ‘box’ resolves all paths rela…