Ark: Set `R_INCLUDE_DIR` and `R_SHARE_DIR` envvars?
These are set by the R launcher shell script but not by ark, resulting in a different environment. RStudio sets them too.
One consequence is that running make -f $R_HOME/etc/Makeconf from inside Ark results in an error because these variables expand to "".
@lionel- what scenarios does this break?
The compilation-database generator in pkgload had to work around the absence of these envvars (and introduced another bug by doing so https://github.com/r-lib/pkgload/pull/288).
RStudio also does this; see e.g.
https://github.com/rstudio/rstudio/blob/74696236366342008aeda8da21beefb502c8c4a9/src/cpp/core/r_util/REnvironmentPosix.cpp#L506-L515
I think ark will want to read and set these as well.
And R_DOC_DIR, see below
> R.home
function (component = "home")
{
rh <- .Internal(R.home())
switch(component, home = rh, bin = if (.Platform$OS.type ==
"windows" && nzchar(p <- .Platform$r_arch)) file.path(rh,
component, p) else file.path(rh, component), share = if (nzchar(p <- Sys.getenv("R_SHARE_DIR"))) p else file.path(rh,
component), doc = if (nzchar(p <- Sys.getenv("R_DOC_DIR"))) p else file.path(rh,
component), include = if (nzchar(p <- Sys.getenv("R_INCLUDE_DIR"))) p else file.path(rh,
component), modules = if (nzchar(p <- .Platform$r_arch)) file.path(rh,
component, p) else file.path(rh, component), file.path(rh,
component))
}
See also https://github.com/posit-dev/positron/issues/4133 for a likely consequence of not setting the include envvar.
Using last Positron-2024.08.0-48.deb in Ubuntu 22, setting R_SHARE_DIR=/usr/share/R/share/ at my ~/.Renviron solve it.
Strange, it doesn't work for me (also Ubuntu 22 / R4.4.1) even if I include in ~/.Renviron:
R_INCLUDE_DIR=/usr/share/R/include
R_SHARE_DIR=/usr/share/R/share
I can see these are set from within Positron using Sys.getenv(). However I still get the error on hover over an R API function in a C file:
'R.h' file not found clang(pp_file_not_found)
EDIT: Sorry - I'm new to VS Code so I realised if I turn off the 'clangd' extension, then at least 'R.h' is found and I get basic completion features.
C function signatures do not seem to be implemented yet though - I'd realistically need this to use as a daily driver.
My understanding is that clangd works best if you can generate a compile_commands.json file, which it can then use to figure out how your project is structured. https://clangd.llvm.org/installation#project-setup
For R specifically, I think you can use bear to generate that file; you could then do something like:
bear -- R CMD INSTALL --preclean .
in your R package directory.
@shikokuchuo see https://github.com/posit-dev/positron/discussions/4534#discussioncomment-10501168 for how to use pkgload to auto generate a compile_commands.json file for use with clangd, you must create one otherwise clangd basically doesn't work
Thanks @kevinushey and @DavisVaughan! It worked after I made a change to pkgload - have submitted this PR.
compile_commands.json is now being generated. Thanks again!
This bites on Fedora too. To clarify - is setting R_INCLUDE_DIR, R_SHARE_DIR and R_DOC_DIR manually in our .Rprofile still the best approach to solving this at the moment (from posit/ron perspective)?
Since this is coming up regularly I prioritised this to the December release.
Since this is coming up regularly I prioritised this to the December release.
Great. Currently without the manual intervention on linux, quite a few packages could be broken (i.e https://github.com/search?q=org%3Acran+%22R.home%28%5C%22share%5C%22%29%22&type=code). The one I've just seen is devtools::spell_check() ...
R> spell_check()
DESCRIPTION does not contain 'Language' field. Defaulting to 'en-US'.
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
In file(con, "r") :
cannot open file '/usr/lib64/R/share/Rd/macros/system.Rd': No such file or directory
Error in `file()`:
! cannot open the connection
Show Traceback
Verified Fixed
Positron Version(s) : 2025.01.0-2
OS Version : OSX
Test scenario(s)
stopifnot(
nzchar(Sys.getenv('R_SHARE_DIR')),
nzchar(Sys.getenv('R_INCLUDE_DIR')),
nzchar(Sys.getenv('R_DOC_DIR'))
)
passes
Link(s) to TestRail test cases run or created: