--- title: "Using RSwitch" output: html_document: toc: true toc_float: true --- ```{r include=FALSE} knitr::opts_chunk$set( fig.retina = 2, comment = "" ) ``` RSwitch is a macOS menubar application that works on macOS 10.14+ and provides handy shortcuts for developing with R on macOS. You can download it from the [landing page](https://rud.is/rswitch/) or contribute to the [development](develop.html) of the application. ## Credits Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone: - [Benjamin Guiastrennec](https://github.com/guiastrennec) for suggesting improvements to the documentation regarding how to use the installer packages from the [R for macOS Developer's Page](https://mac.r-project.org/) without clobbering existing R Framework installs. - [Xavier Adam](https://github.com/xvrdm) for [adding books to the RSwitch library](https://github.com/hrbrmstr/RSwitch/pull/4). ## Basic/Core Usage After downloading and running the application a new menubar item will appear and the core menu will look something like this: ![](menu-info.png) The initial and primary feature of the RSwitch app was to enable switching what your system considers to be the "current" version of R. To understand how that is "computed", you should use the "R Frameworks Directory" option which opens up `/Library/Frameworks/R.framework/Versions` in the Finder so you can browse and manipulate the contents of that directory tree on your own. ```{r} fs::dir_tree(path = "/Library/Frameworks/R.framework/Versions", recurse = FALSE) ``` The "R Framework" is, well, *R* on your macOS system. All of the necessary supporting libraries, code, pacakges, configuration elements, etc. exist in the framework directory. Here is the top-level contents of the `3.5` version of the R Framework: ```{r} fs::dir_tree(path = "/Library/Frameworks/R.framework/Versions/3.5", recurse = 1) ``` When you download and run the [official R macOS installer](https://cran.r-project.org/bin/macosx/) files are installed into a versioned tree and the `Current` symbolic link is updated to point to what you just installed. By making all of the installed resources depend on the `Current` symbolic link, the R Core team made it possible to switch R versions just by changing that link. For example, The `R` console application in `/usr/local/bin` is a symbolc link to: `/usr/local/bin/R@ -> /Library/Frameworks/R.framework/Resources/bin/R` The `Resources` directory (and everything else in `/Library/Frameworks/R.framework/` uses the `Current` symbolic link to get to the correct targets): - `Headers@ -> Versions/Current/Headers` - `Libraries@ -> Versions/Current/Resources/lib` - `PrivateHeaders@ -> Versions/Current/PrivateHeaders` - `R@ -> Versions/Current/R` - `Resources@ -> Versions/Current/Resources` - `Versions/` For the most control, you can install a coexisting version of R **oldrel**-1, **oldrel** (as of the date this document was created those would be R 3.4 and R 3.5), current **release** (R 3.6) and **devel** (3.7) by hand by going to the [R for macOS Developer's Page](https://mac.r-project.org/) and downloading the `tar.gz` version of those distributions: ![](r-macos-downloads.png) Here are direct `https` links to the tarballs: - [R 3.4](https://mac.r-project.org/mavericks/R-3.4-branch/R-3.4-branch-mavericks-sa-x86_64.tar.gz) (oldrel-1) - [R 3.5](https://mac.r-project.org/el-capitan/R-3.5-branch/R-3.5-branch-el-capitan-sa-x86_64.tar.gz) (oldrel) - [R 3.6](https://mac.r-project.org/el-capitan/R-3.6-branch/R-3.6-branch-el-capitan-sa-x86_64.tar.gz) (current) - [R 3.7](https://mac.r-project.org/el-capitan/R-devel/R-devel-el-capitan-sa-x86_64.tar.gz) (devel) Once downloaded, you can fire up a terminal prompt, head to the root directory (i.e. `cd /`) and run `tar -xvzf path-to-thing-you-just-downloaded` to lay out the contents of the tarball onto the filesystem. You can also use the `.pkg` versions if you prefer a clicky-installer wizard, but these installers will remove any previous versions of the framework (kinda defeating the purpose). You can still use the `.pkg` format by heading over to the command line and using `pkgutil --forget` to prevent said clobbering behavior (as noted in [Section 4.2](https://cran.rstudio.org/doc/manuals/R-admin.html#Uninstalling-under-macOS) of _R Installation and Administration_. For example: ```{bash eval=FALSE} sudo pkgutil --forget org.r-project.R.el-capitan.fw.pkg \ --forget org.r-project.x86_64.tcltk.x11 \ --forget org.r-project.x86_64.texinfo \ --forget org.r-project.R.el-capitan.GUI.pkg ``` Once you install one of these versions, `Current` gets manipulated to point to it. You can either `rm` the existing symbolic link and `ln -s` a new one or _just use RSwitch_! Upon initial click, RSwitch figures out which versions of R you have installed and lets you switch them just by selecting the versioned menu item. When the change is made you get a handy notification letting you know the action performed successfully and which R version you changed to: ![](r-change-notify.png)