r-lib / rig

The R Installation Manager
MIT License
630 stars 22 forks source link

[Windows] Possibly include (sym)links to current *.exe files in c:\Program Files\R\bin #189

Open morphatic opened 1 year ago

morphatic commented 1 year ago

In addition to the *.bat files in C:\Program Files\R\bin it would be great if there were also copies or symlinks to the current R.exe and RScript.exe.

I use Git Bash running in Windows Terminal (instead of PowerShell or CMD). This allows me to use the *nix style of almost everything without having to install WSL2. I ❤️ that rig adds C:\Program Files\R\bin to the PATH and puts the current version of R in that location. It's very intuitive.

However, Git Bash doesn't recognize *.bat files as being executables (although you can run them if you type out the whole path).

I'm not a Rustacean, but I suspect that somewhere in sc_system_make_links() it would mean creating a symbolic link to the R.exe and Rscript.exe files in, e.g. C:\Program Files\R\R-4.3.1\bin. Is something like this pretty straightforward?

What I currently do now (manually) to achieve this:

  1. Open Windows Terminal as administrator
  2. Navigate to C:\Program Files\R
  3. Create a symbolic link to the current version, e.g. ln -s ../R-4.3.1 current
  4. Make sure that C:\Program Files\R\current\bin is added to my PATH

About My Setup Windows 11 on x64. Installed rig with scoop. Using Git Bash profile inside of Windows Terminal as my default terminal environment.

gaborcsardi commented 1 year ago

I have some vague memories that symlinks didn't work well on Windows, that's why I started creating the .bat files. (On other platforms rig uses symlinks.)

But let me experiment with it, if is works for you, that's a good start. It is possible that they are OK on modern Windows, but not on older Windows, but then we could still use them on newer Windows.

emilyriederer commented 9 months ago

Just upvoting this one! I'm loving rig as a project, but running into similar friction with just the .bat files specifically in conjunction with the Quarto VS Code extension. (I don't think details are really important, but happy to share if interested.) Right now, I'm solving for it by setting the QUARTO_R environment variable separately and pointing to the bin/ file for the specific version, but it's definitely less elegant than fully embracing rig

DavisVaughan commented 1 week ago

@gaborcsardi I know that in uv they use junction points on Windows rather than symlinks and that seems to work for them. Not sure if that could work here, but its possible https://github.com/astral-sh/uv/blob/bd3c4626744aeb5cd1e813b45dbde21f2cdc6335/crates/uv-fs/src/lib.rs#L45-L50

Looks like junctions can't point at individual files, only at directories but maybe we can still make that work https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions#junctions

DavisVaughan commented 1 week ago

Its possible this is the symlink issue on Windows:

As opposed to symlinks, junction does not require administrator privileges during creation. (However starting with Windows 10 Insiders build 14972, symlinks can be created without needing to elevate the console as administrator)^1.

Mentioned here in the readme of junction https://crates.io/crates/junction

gaborcsardi commented 1 week ago

I think it was simply that older windows did not have symlinks at all, at least not on all types of file systems. (rig initially supported Windows 7!) I think admins rights are ok, rig already needs to run as admin to change these links.