Like many R users, I had been using R with RStudio since 2013 which was only two years after its initial release. Although RStudio was much simpler than it is today, its simplicity and straightforwardness made it a great, if not the best, choice for most R users I believe.
However, when my work gets more and more complicated, sometimes I find it painful to use the free RStudio Server in some scenario. For example, when I need to work with multiple interactive R sessions on one server to run two scripts in the same projects at the same time and view the output side by side, it is not easy.
If I need to interactively run a script in another project, I had to switch to that project. But it also means I need to either save or drop the workspace of the current project. When the workspace contains some huge data frames, it won’t be feasible to do so as it would take a lot of time to save or restore the workspace.
Sometimes, I need to work with multiple programming languages. Some of my projects contains a lot of feature generating functions such as time-series functions. They are implemented in C++ for better performance but wrapped in R functions for easier programming and analysis with existing data. But in many cases, I have to work with R and C++ side by side. The C++ support in RStudio is a bit too basic to be productive.
Another case is that I might need to write some HTML, CSS, and JavaScript when I work with shiny apps such as live trading dashboard. The web development stack is a whole new realm but they are just supported at a basic level in RStudio.
As my work develops, it is more likely that I need to work with multiple servers. In one scenario, these servers are independent and designed to perform different tasks but all of them cumulate some data. If I need to analyze the data on each server, installing RStudio Server on each of them does not look like the right solution.
Another scenario is that I use a HPC cluster and I need to submit jobs to the scheduler which sends jobs to the compute nodes where docker containers are created to run the jobs. In this case, it is not easy to write the task script since the cluster nodes that run the tasks do not run RStudio server.
Also, the engineering demands increase as my work projects become more complicated. When the project gets larger, it is getting more and more difficult to maintain. Without more powerful engineering tools, it won’t be easy to search by symbol, rename a symbol or find references project wide.
Another important thing in RStudio is that the code editor and the interactive R session are bundled. When the R session is busy, the editor is usually not responsive any more. When the R session crashes due to some bug in the compiled code, the editor could not surive either. If there are unsaved changes, there is a risk that the code might be lost. This usually happens when we do heavy parallel computing.
Despite all these reasons, the worst case of all is in some cases the server could only be accessible through SSH and RStudio Server is not available at all for network or security reasons.
I encoutered all above scenarios in my work using R and I started trying to use R in VS Code two years ago. Before that, I have been using VS Code to do C++ development for a few years and the user experience has been constantly improved through time.
In 2019, I decided to switch from RStudio to VS Code and I’ve been hoping to see how far I can go using R without RStudio. I’ve been participated in the development of vscode-R, R language server, and some other related packages (e.g. lintr, styler) since then. Today, I’ve been working with R in VS Code for more than two years yet RStudio is still the standard we are looking at when we consider the features and desired behavior of how we should interact with R in VS Code.
The great things I appreciate about RStudio is that it just works out of the box, almost zero configuration. Its intuitive all-in-one screen layout and nice integration of R packags make RStudio extremely user friendly and easy to work with.
It is quite important to notice the fact that most R users are not professional developers but reearchers and those who need to work with data. The top concern is probably whether the coding environment makes them more productive to solve their problems rather than how powerful the tool is. It is designed more through the lens of a data scientist than a software engineer.
VS Code is a free open-source code editor. The biggest difference between VS Code and RStudio is that VS Code is not specifically design for certain programming languages.
It has built-in support of the Language Server Protocol to enable code editing features such as completion, signature, diagnostics, hover, go to definition, etc. for any programming language that has an implementation of the language server. It also has Debug Adapter Protocol to allow users to interactively debug any program written in any language as long as there is a supported debugger. It also has built-in git support and tons of extensions to improve the editor in different aspects.
As VS Code keeps evolving, the support of some of the most popular languages are constantly improved. They support most of the features VS Code has to offer and the programming experience with these languages is awesome.
The most exciting thing about VS Code is that thousands of extensions are available in the VS Code marketplace. You can use whatever makes you more productive. Remote Development via SSH, Windows Subsystem for Linux, and Containers and Live colaboration are two of the extensions of VS Code I find extremely powerful. Also, the in-depth integration of GitHub makes it much easier to work with the open source projects hosted on the website.
In summary, I recommend that you try using R in VS Code if you:
- Need to work with multiple R projects or R terminals on a remote server simultaneously.
- Need to work with multiple programming languages such as Python, C++, or web development stack and need powerful language supports.
- Need to work with multiple servers or containers and want to have a unified R development experience.
- Need more responsive and powerful engineering tools such as symbol highlight, find references, rename symbol, etc. integrated to the IDE.
- Need to ensure the development environment and interactive R sessions are separated so that one crash does not affect the other.
- Have limited or no access to RStudio Server on a remote server.
- Need live collaboration with others such as pair programming, demonstrating and teaching.