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

renv::load() duplicating paths in the PATH environment variable #1095

Closed
lucygarner opened this issue Oct 13, 2022 · 8 comments · Fixed by #1245
Closed

renv::load() duplicating paths in the PATH environment variable #1095

lucygarner opened this issue Oct 13, 2022 · 8 comments · Fixed by #1245
Labels
activate/init/load 🥾 bug an unexpected problem or unintended behavior

Comments

@lucygarner
Copy link

Hi,

renv::load() appears to be duplicating some of the paths in the PATH environment variable.

In my R project, I run the following prior to loading renv.
renv:::renv_envvar_get("PATH")

[1] "/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS"

Then I run renv::load() and renv:::renv_envvar_get("PATH").

[1] "/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/X11/bin:/Library/TeX/texbin:/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS"

I have RENV_AUTOLOADER_ENABLED = FALSE in my .Renviron.

Best wishes,
Lucy

@kevinushey
Copy link
Collaborator

IIUC these are the two path entries getting duplicated:

/Users/lucy/Library/r-miniconda/condabin
/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin

Do you know where these path entries are originally being set?

The output of the following might be helpful:

trace(Sys.setenv, quote({
  dots <- list(...)
  if ("PATH" %in% names(dots)) {
    print(rlang::trace_back())
  }
}), print = FALSE)
renv::load()

@lucygarner
Copy link
Author

Yes correct.

trace(Sys.setenv, quote({
  dots <- list(...)
  if ("PATH" %in% names(dots)) {
    print(rlang::trace_back())
  }
}), print = FALSE)

Tracing function "Sys.setenv" in package "base"
[1] "Sys.setenv"

Is that what you wanted me to run?

@kevinushey
Copy link
Collaborator

Please also run renv::load() after running that code.

@lucygarner
Copy link
Author

I had to run renv::load() prior to trace since otherwise I get an error that there is no package called rlang.

So I ran:

renv::load()
trace(Sys.setenv, quote({
    dots <- list(...)
    if ("PATH" %in% names(dots)) {
        print(rlang::trace_back())
    }
}), print = FALSE)
renv::load()

And got the following:

    ▆
 1. └─renv::load()
 2.   └─renv:::renv_load_path(project)
 3.     └─base::Sys.setenv(PATH = paste(mix, collapse = .Platform$path.sep))
    ▆
 1. └─renv::load()
 2.   └─renv:::renv_load_python(project, lockfile$Python)
 3.     └─renv:::renv_envvar_prepend("PATH", bindir)
 4.       └─renv:::renv_envvar_modify(envvar, value, TRUE)
 5.         ├─base::do.call(Sys.setenv, as.list(new))
 6.         └─base (local) `<fnctnWtT>`(PATH = "/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/X11/bin:/Library/TeX/texbin:/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS")
    ▆
 1. └─renv::load()
 2.   └─renv:::renv_load_python(project, lockfile$Python)
 3.     └─renv:::renv_envvar_prepend("PATH", dirname(conda))
 4.       └─renv:::renv_envvar_modify(envvar, value, TRUE)
 5.         ├─base::do.call(Sys.setenv, as.list(new))
 6.         └─base (local) `<fnctnWtT>`(PATH = "/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/X11/bin:/Library/TeX/texbin:/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS")

kevinushey added a commit that referenced this issue Oct 13, 2022
@kevinushey
Copy link
Collaborator

Thanks! I believe this will be fixed via 97f6620.

@lucygarner
Copy link
Author

lucygarner commented Oct 14, 2022

I gave it a go. This doesn't seem to have fixed it unfortunately.

packageVersion("renv")

[1] ‘0.16.0.15’

Sys.getenv("PATH")

[1] "/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS"

renv::load()

* Project '~/Documents/2022/devel/10x/R' loaded. [renv 0.16.0-15]

Sys.getenv("PATH")

[1] "/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/opt/X11/bin:/Library/TeX/texbin:/Users/lucy/Library/r-miniconda/condabin:/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin:/Users/lucy/Applications/quarto/bin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS"

The following paths are still duplicated:
/Users/lucy/Documents/2022/devel/10x/R/.conda_env/bin
/Users/lucy/Library/r-miniconda/condabin

Best wishes,
Lucy

@kevinushey
Copy link
Collaborator

Thanks -- I'll have to take another look and see if I can figure out why...

@hadley hadley added bug an unexpected problem or unintended behavior activate/init/load 🥾 labels Apr 25, 2023
@hadley
Copy link
Member

hadley commented May 11, 2023

I'm still seeing this too:

Sys.setenv("PATH" = "/opt/homebrew/bin/:/bin")
renv::scaffold()
#> * renv infrastructure has been generated for project "/private/tmp/RtmpQVJX13/reprex-13dda40d69662-odd-tuna".
strsplit(Sys.getenv("PATH")[[1]], ":")
#> [[1]]
#> [1] "/opt/homebrew/bin/" "/bin"
renv::load()
strsplit(Sys.getenv("PATH")[[1]], ":")
#> [[1]]
#> [1] "/opt/homebrew/bin/" "/opt/homebrew/bin/" "/bin"

Created on 2023-05-11 with reprex v2.0.2

hadley added a commit that referenced this issue May 11, 2023
kevinushey pushed a commit that referenced this issue May 11, 2023
* Don't duplicate paths

Fixes #1095

* Improve tests

* Revert output changes

* WS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
activate/init/load 🥾 bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants