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

Multiple installations of the same R version #63

Closed
lazappi opened this issue May 20, 2022 · 6 comments
Closed

Multiple installations of the same R version #63

lazappi opened this issue May 20, 2022 · 6 comments
Labels
feature a feature request or enhancement

Comments

@lazappi
Copy link

lazappi commented May 20, 2022

Hi

Thanks for the great tool, I think this will make lots of people's lives easier 🎉 ! I have been playing around with getting two installations of the same R version to work. Probably a fairly niche thing so not suggesting you add it as a feature (unless there is demand) but thought I would post my solution in case it was helpful to anyone (and in case there are issues I haven't come across yet). My use case is to have two versions of R 4.2 installed, one with Bioconductor release (for analysis) and one with Bioconductor devel (for development) and to be able to switch between the two as needed.

These are the steps that worked for me on MacOS:

  1. Install the desired R version.
rim install release
  1. Rename the installed directory
mv /Library/Frameworks/R.framework/Versions/4.2 /Library/Frameworks/R.framework/Versions/4.2-bioc
  1. Modify the main R script so that all paths point to the new location
vim /Library/Frameworks/R.framework/Versions/4.2-bioc/Resources/bin/R

Search for all occurrences of the installed R version and modify them to match the new path (eg. change all 4.2 to 4.2-bioc)

  1. Modify the base Renviron file to set the default user library path
vim /Library/Frameworks/R.framework/Versions/4.2-bioc/Resources/etc/Renviron

Find where R_LIBS_USER is set and modify it to point to the new installation directory.

R_LIBS_USER=${R_LIBS_USER:-'/Users/user/Library/R/x86_64/4.2-bioc/library'}

(I feel like there should be a way to do this without hard coding a path but haven't really looked into it)

  1. Re-install the desired R version.
rim install release

After this I am able to switch between 4.2 and 4.2-bioc with both installations having .libPaths() correctly set to different directories. You probably lose the ability to make updates for new R versions but worth it for me to be able to easily switch between these two environments.

@gaborcsardi
Copy link
Member

Unfortunately it is not that simple, because all shared libraries are hard-wired to link to the original installation:

❯ otool -L /Library/Frameworks/R.framework/Versions/4.1/Resources/library/stats/libs/stats.so
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/stats/libs/stats.so:
	stats.so (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib (compatibility version 4.1.0, current version 4.1.3)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libgfortran.5.dylib (compatibility version 6.0.0, current version 6.0.0)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libR.dylib (compatibility version 4.1.0, current version 4.1.3)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1673.126.0)

This is even true for non-base CRAN packages:

❯ R-4.1 -q -e '.libPaths()[1]'
> .libPaths()[1]
[1] "/Users/gaborcsardi/Library/R/x86_64/4.1/library"

❯ otool -L /Users/gaborcsardi/Library/R/x86_64/4.1/library/filelock/libs/filelock.so
/Users/gaborcsardi/Library/R/x86_64/4.1/library/filelock/libs/filelock.so:
	filelock.so (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libR.dylib (compatibility version 4.1.0, current version 4.1.2)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1853.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

So you would need to modify these paths using install_name_tool for every shared lib in base R, and then also after every single package installation.

OTOH, you don't need two separate R installations if the only difference is in the user package libraries. You can modify R_LIBS_USER in .Renviron to switch between two user libraries.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label May 20, 2022
@lazappi
Copy link
Author

lazappi commented May 23, 2022

Thanks, I would not have worked that out! I know that you can use .Renviron but I have found that to be more work in the past, particularly when using RStudio. I had a similar setup with two R installations that worked fine with the rswitch tool. I was hoping to be able to do the same thing here but maybe the extra things you have built around the installation make that impossible and I should just go back to what I had before.

@gaborcsardi
Copy link
Member

Yes, #66 is basically what you want, multiple user libraries for the same R version. We'll have that soon.

@gaborcsardi
Copy link
Member

FYI: the pre-release at https://github.com/r-lib/rig/releases/tag/v0.3.1pre now supports multiple libraries and switching between them. This is currently an experimental feature and it might change in the future. Feedback is welcome.

@lazappi
Copy link
Author

lazappi commented May 30, 2022

I have only started using it but works perfectly so far (I like the menu bar app as well) 🎉! Thanks for working on this so quickly.

@gaborcsardi
Copy link
Member

I am going to close this now. If we need more features related to this we'll create new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants