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 or contribute to the development of the application.
Many thanks to the following folks for their contributions to the project to help make RSwitch better for everyone:
After downloading and running the application a new menubar item will appear and the core menu will look something like this:
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.
fs::dir_tree(path = "/Library/Frameworks/R.framework/Versions", recurse = FALSE)
/Library/Frameworks/R.framework/Versions ├── 2.14 ├── 3.5 ├── 3.6 ├── 3.7 ├── 4.0 ├── 4.1 └── Current
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:
fs::dir_tree(path = "/Library/Frameworks/R.framework/Versions/3.5", recurse = 1)
/Library/Frameworks/R.framework/Versions/3.5 ├── Headers ├── PrivateHeaders │ ├── Defn.h │ ├── Errormsg.h │ ├── Fileio.h │ ├── Graphics.h │ ├── GraphicsBase.h │ ├── IOStuff.h │ ├── Internal.h │ ├── Makefile.in │ ├── Makefile.win │ ├── Parse.h │ ├── Print.h │ ├── R.h │ ├── R_ext │ ├── Rconnections.h │ ├── Rdefines.h │ ├── Rdynpriv.h │ ├── Rembedded.h │ ├── Rgraphics.h │ ├── Rinlinedfuns.h │ ├── Rinterface.h │ ├── Rinternals.h │ ├── Rmath.h0.in │ ├── Rmodules │ ├── S.h │ ├── Startup.h │ ├── config.h │ ├── config.h.in │ ├── rlocale.h │ ├── stamp-h.in │ └── vg ├── R └── Resources ├── COPYING ├── Info.plist ├── R ├── Rscript ├── SVN-REVISION ├── bin ├── doc ├── etc ├── fontconfig ├── include ├── lib ├── library ├── man1 ├── modules ├── share └── tests
When you download and run the official R macOS installer 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
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
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.5 and R 3.6), current release (R 4.0) and devel (4.1) by hand by going to R for macOS and downloading the
tar.gz version of those distributions:
Here are direct
https links to the tarballs:
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 of R Installation and Administration. For example:
sudo pkgutil --forget org.r-project.R.el-capitan.fw.pkg \ # may need to use high-sierra vs el-capitan --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:
The main goal of the package was to make it easier to switch the current version of R to something else. If you have that need, chances are that you are playing with the development version of R and said version has nightly builds.
Similarly, if you are living on the cutting edge of R you are also likely doing the same with RStudio dailies.
RSwitch provides two handy menu item shortcuts to download either of those resources, but it expects you do some work to use them. When you select either of the “Download latest&hellip” items some checks are performed (mostly to find the current version of the latest RStudio daily) and if it finds either the r-devel tarball or the exact same version of the RStudio disk image in the
~/Downloads directory it will let you know you need to clean up after yourself first:
If RSwitch can download the requested resource it will do so in the background and grey out the selected item until the process is complete. When the process is complete (or errors) a notification will be sent:
and the Finder will open up to
~/Downloads with the target file selected.
Since RSwitch is designed to help you work with R on macOS it seemed only fitting to provide some handy links to resources like the R for macOS page, the CRAN R page, RStudio dailies link, etc. They’re all available via the fairly obvious sub-menu:
and each item will open up in your default web browser. (File an issue if you’d like more links added)
Since the theme of RSwitch is, well, switching it, further, seemed only fitting to allow you to make any open RStudio or R GUI instance active from the app:
The list is presented in app order (RStudio first since it’s super likely that’s what most macOS R folk are using) and then in app launch order (oldest on top). As shown, if RSwitch can detect what the open RStudio project or package is, that name gets added to the switching title.
While being able to switch to running instances is fine, it would also be handy to be able to launch RStudio or R GUI from the menubar app. If none are currently running you can launch them with the obviously named menu items. If you hold down
<Control> as you click on the RSwitch icon you’ll be given the opportunity to launch new, concurrent instances of either application.
RSwitch is under active, heavy development. Even when the development cycle dies down it will receive updates as bugs are fixed and new features are added. Rather than make you subscribe to a blog or monitor Twitter or social coding sites RSwitch now lets you check for updates right within the app. If there are no updates you get a notification telling you so:
otherwise, a link will open in your default browser so you can download the latest version.
Starting with version 1.5.0, RSwitch is now your control center for organizing and accessing RStudio Server instances:
Creating a new connection is just a simple form:
and you can then launch a task-specific browser for each instance you have defined:
This allows you to keep RStudio Server work separate from your internet browsing, creating a more focused workspace that you never have to worry about accidentally closing. Window size & position are preserved across launches, too and the keystrokes you are used to in RStudio Desktop on macOS are the same in this task-specific browser.
File uploads and downloads (“exports”) are also now supported.
There’s a minimal preferences system for showing/hiding the dock icon and for enabling background checks for and notifications when new RStudio Dailies are available.
Another (new) preference is “Ensure RStudio opens R/Rmd files”. Xcode and other developer-oriented programs seem to love to takeover either
.Rmd (sometimes both) and loading Xcode can take a while. Setting this preference will enable an hourly check for who owns those extensions and forces them back to RStudio in the event they are changed.
If you like RSwitch enough to keep it running all the time, just drag the item to the “Login Items” table of your user in the “Users & Groups” pane of “System Preferences”
There’s a new command-line switcher for folks who would rather not interact with a menu to change R versions.
RSwitch.app comes with
rswitch-cmd tucked into
/Applications/RSwitch.app/Contents/Resources/. You can make it easier to type by making a symbolic link in
/usr/local/bin/ (or your preferred path that’s on
$ ln -s /Applications/RSwitch.app/Contents/Resources/rswitch-cmd /usr/local/bin/rswitch
Firing off just
rswitch will bring up a list of available R installs with an asterisk signifying which one is active:
$ rswitch 2.14 (incomplete) 3.5 3.6 3.7 4.0 * 4.1
Just call it with the version you want to switch to and you are ready to go (you can also use
-l if you like typing more than you need to):
$ rswitch 4.1 $ rswitch --list 2.14 (incomplete) 3.5 3.6 3.7 4.0 4.1 *
You’ll receive an error message if the version specified cannot be found:
$ rswitch 4.4 R version 4.4 not found.
All non-successful operations will set a non-zero exit code in the event you are using the command-line utility in scripts.
If you’re having trouble with RSwitch or have a feature request, head on over to any of the following social coding sites and file an issue:
Copyright © 2019 Bob Rudis. All rights reserved.