Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discover R on PATH on windows (#4190)
Addresses #3702 Also related to #3677 and #3868 This PR deals with this situation: * R is installed in a non-default location. * We can't learn about this R installation from the registry (either because registry keys were not written or permissions are keeping us from reading the registry). * The user has arranged for R to be discovered on the PATH. ### QA Notes To experience the before vs. after, you need very specific setup. We're trying to imitate a user with R in a non-default location and no permission to access the registry. To make R discoverable, this user is relying solely on the fact that they've put R on their PATH. If you don't have a completely locked down corporate Windows laptop, follow the instructions below to fake it 😬 Before: in a released version of Positron (or a release built before this PR gets merged), the R version set up as described below WILL NOT be discovered by Positron. After: with this PR, the R version set up as described below WILL be discovered by Positron. You can also see more about discovery in the Positron R Extension output channel. (It is expected that you will see that some R versions are discovered more than once.) You should see new logging messages like this: `2024-08-01 16:19:27.712 [info] Possibly found R on PATH: C:\notADefaultFolder\R-4.2.3\bin\x64\R.EXE.` --- 1. **OS must be Windows**. At least one R version needs to be: 2. **Installed in an unusual place** where Positron will not automatically discover it. TL;DR is to install somewhere other than `C:\Program Files` or `C:\R`. For a more precise definition, here is the [actual code](https://github.com/posit-dev/positron/blob/4a05a525c7da4bb2778490eb6a244e0f4b54ccef/extensions/positron-r/src/provider.ts#L228-L236). For example, I chose to put this non-default R installation in `C:\notADefaultFolder` . This will be easiest to do if you use the CRAN installer directly (so, not using rig). You can get old versions of R here: [Previous releases of R for Windows (r-project.org)](https://cran.r-project.org/bin/windows/base/old/) <img width="588" alt="select-destination" src="https://github.com/user-attachments/assets/9f3a7e90-9630-430a-b70c-4b44278776a7"> 4. **Not recorded as the current version of R in the registry**. Make sure it is NOT stored as the `InstallPath` subkey in these locations: - `HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R64` - `HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R` - `HKEY_CURRENT_USER\SOFTWARE\R-core\R64` - `HKEY_CURRENT_USER\SOFTWARE\R-core\R` - `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\R-core\R` - `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\R-core\R64` - `HKEY_CURRENT_USER\SOFTWARE\WOW6432Node\R-core\R` - `HKEY_CURRENT_USER\SOFTWARE\WOW6432Node\R-core\R64` Ways to accomplish this: - Don't let the installer write to the registry. <img width="589" alt="save-version-registry" src="https://github.com/user-attachments/assets/cabee89d-7f34-443d-86f7-a30f41f9294c"> - Manually delete keys via the Registry Editor. - Install some *other* version of R after this one and let *that* version be recorded in the registry as the current version of R. - Use utilities that ship with R: > After installation you can add the Registry entries by running `RSetReg.exe` in a sub-folder of the `bin` folder, and remove them by running this with argument `/U`. Note that this requires administrative privileges unless run with argument `/Personal` and neither sets up nor removes the file associations. 5. **Have its `bin\x64` or `bin` directory on the PATH** (system or user). Neither rig nor the CRAN installer do this, so this has to be done explicitly. For example, the path I added to my user PATH is `C:\notADefaultFolder\R-4.2.3\bin\x64`. There seem to be many ways to do this, but here's what I did: Go to About your PC \> Advanced system settings (in list on the right) \> Environment Variables. Add an entry to `Path` for the user or the system. <img width="531" alt="edit-environment-variable" src="https://github.com/user-attachments/assets/2f03db69-c373-4a8e-9439-7ed6f8258395"> You'll need to restart any shells or maybe log out / log in for this to take effect. Test that this has worked by launching R in a terminal and confirm it's launching the intended version. I verified this in cmd.exe, PowerShell, and Git Bash FWIW. --------- Signed-off-by: Jennifer (Jenny) Bryan <[email protected]> Co-authored-by: Jonathan <[email protected]>
- Loading branch information