Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ark: Set R_INCLUDE_DIR and R_SHARE_DIR envvars? #3637

Closed
lionel- opened this issue Jun 25, 2024 · 14 comments
Closed

Ark: Set R_INCLUDE_DIR and R_SHARE_DIR envvars? #3637

lionel- opened this issue Jun 25, 2024 · 14 comments
Assignees
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: r os-linux Linux issue

Comments

@lionel-
Copy link
Contributor

lionel- commented Jun 25, 2024

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- lionel- added bug Something isn't working lang: r area: kernels Issues related to Jupyter kernels and LSP servers labels Jun 25, 2024
@juliasilge juliasilge added this to the Future milestone Jul 1, 2024
@juliasilge
Copy link
Contributor

@lionel- what scenarios does this break?

@lionel-
Copy link
Contributor Author

lionel- commented Jul 2, 2024

The compilation-database generator in pkgload had to work around the absence of these envvars (and introduced another bug by doing so r-lib/pkgload#288).

@kevinushey
Copy link
Contributor

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.

@DavisVaughan
Copy link
Contributor

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

@lionel-
Copy link
Contributor Author

lionel- commented Jul 29, 2024

See also #4133 for a likely consequence of not setting the include envvar.

@jrosell
Copy link

jrosell commented Aug 27, 2024

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

@lionel- lionel- added the os-linux Linux issue label Aug 28, 2024
@shikokuchuo
Copy link

shikokuchuo commented Sep 4, 2024

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.

@kevinushey
Copy link
Contributor

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.

@DavisVaughan
Copy link
Contributor

@shikokuchuo see #4534 (comment) 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

@shikokuchuo
Copy link

shikokuchuo commented Sep 5, 2024

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!

@TimTaylor
Copy link

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

@lionel- lionel- modified the milestones: Future, 2024.12.0 Pre-Release Oct 29, 2024
@lionel-
Copy link
Contributor Author

lionel- commented Oct 29, 2024

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

@lionel- lionel- self-assigned this Oct 29, 2024
@TimTaylor
Copy link

TimTaylor commented Oct 29, 2024

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

lionel- added a commit that referenced this issue Nov 27, 2024
## Positron Notes

### Release Notes

#### New Features

- The variable pane now supports labels from the {haven} package
(#5327.

- The variable pane has improved support for formulas
(#4119).

#### Bug Fixes

- Assignments in function calls (e.g. `list(x <- 1)`) are now detected
by the missing symbol linter to avoid annoying false positive
diagnostics (#3048). The downside is that this causes
false negatives when the assignment happens in a call with local scope,
e.g. in `local()` or `test_that()`. In these cases the nested
assignments will incorrectly overlast the end of the call. We prefer to
be overly permissive than overly cautious in these matters.

- The following environment variables are now set in the same way that R
does:

  - `R_SHARE_DIR`
  - `R_INCLUDE_DIR`
  - `R_DOC_DIR`

  This solves a number of problems in situations that depend on these
variables being defined
(#3637).
lionel- added a commit that referenced this issue Nov 27, 2024
### Release Notes

#### New Features

- The variable pane now supports labels from the {haven} package
(#5327.

- The variable pane has improved support for formulas
(#4119).

#### Bug Fixes

- Assignments in function calls (e.g. `list(x <- 1)`) are now detected
by the missing symbol linter to avoid annoying false positive
diagnostics (#3048). The downside is that this causes
false negatives when the assignment happens in a call with local scope,
e.g. in `local()` or `test_that()`. In these cases the nested
assignments will incorrectly overlast the end of the call. We prefer to
be overly permissive than overly cautious in these matters.

- The following environment variables are now set in the same way that R
does:

  - `R_SHARE_DIR`
  - `R_INCLUDE_DIR`
  - `R_DOC_DIR`

This solves a number of problems in situations that depend on these
variables being defined
(#3637).

<!-- Thank you for submitting a pull request.
If this is your first pull request you can find information about
contributing here:
  * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md

We recommend synchronizing your branch with the latest changes in the
main branch by either pulling or rebasing.
-->

<!--
  Describe briefly what problem this pull request resolves, or what
  new feature it introduces. Include screenshots of any new or altered
  UI. Link to any GitHub issues but avoid "magic" keywords that will 
  automatically close the issue. If there are any details about your 
approach that are unintuitive or you want to draw attention to, please
  describe them here.
-->
@testlabauto
Copy link
Contributor

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:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: r os-linux Linux issue
Projects
None yet
Development

No branches or pull requests

8 participants