positron icon indicating copy to clipboard operation
positron copied to clipboard

Ark: Set `R_INCLUDE_DIR` and `R_SHARE_DIR` envvars?

Open lionel- opened this issue 1 year ago • 5 comments

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- avatar Jun 25 '24 11:06 lionel-

@lionel- what scenarios does this break?

juliasilge avatar Jul 01 '24 20:07 juliasilge

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).

lionel- avatar Jul 02 '24 08:07 lionel-

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.

kevinushey avatar Jul 09 '24 09:07 kevinushey

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))
}

DavisVaughan avatar Jul 09 '24 09:07 DavisVaughan

See also https://github.com/posit-dev/positron/issues/4133 for a likely consequence of not setting the include envvar.

lionel- avatar Jul 29 '24 14:07 lionel-

Using last Positron-2024.08.0-48.deb in Ubuntu 22, setting R_SHARE_DIR=/usr/share/R/share/ at my ~/.Renviron solve it.

jrosell avatar Aug 27 '24 15:08 jrosell

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.

shikokuchuo avatar Sep 04 '24 18:09 shikokuchuo

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.

kevinushey avatar Sep 04 '24 20:09 kevinushey

@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

DavisVaughan avatar Sep 04 '24 20:09 DavisVaughan

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!

shikokuchuo avatar Sep 05 '24 10:09 shikokuchuo

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)?

TimTaylor avatar Oct 28 '24 22:10 TimTaylor

Since this is coming up regularly I prioritised this to the December release.

lionel- avatar Oct 29 '24 09:10 lionel-

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

TimTaylor avatar Oct 29 '24 09:10 TimTaylor

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:

testlabauto avatar Dec 02 '24 19:12 testlabauto