Top 5 Tips for RStudio (Posit) Workbench and Desktop
RStudio recently announced the renaming of RStudio <del>Server Pro</del> to RStudio Workbench (Posit Workbench). Along with the relabel, some <a href="https://www.rstudio.com/products/rstudio/release-notes/" target="_blank" rel="noopener noreferrer">updates and new features</a> were added. In this blog, we will discuss our 5 favorite tips for more efficient use of RStudio Workbench (also applicable for RStudio Desktop). Note: At the time of writing this article, Posit PBC was RStudio PBC. We use RStudio and Posit interchangeably in this text (e.g. RStudio Workbench == Posit Workbench). <ul><li><a href="#anchor-1" target="_blank" rel="noopener noreferrer">R</a></li><li><a href="#anchor-2" target="_blank" rel="noopener noreferrer">RStudio</a><ul><li><a href="#anchor-3" target="_blank" rel="noopener noreferrer">1) Shortcuts</a></li><li><a href="#anchor-4" target="_blank" rel="noopener noreferrer">2) Multi-Column View</a></li><li><a href="#anchor-5" target="_blank" rel="noopener noreferrer">3) Finding Functions & Variables</a></li><li><a href="#anchor-6" target="_blank" rel="noopener noreferrer">4) Multi-Cursor Editing</a></li><li><a href="#anchor-7" target="_blank" rel="noopener noreferrer">5) Investigate Function Source Code & Documentation</a></li></ul> <h2 id="anchor-1">R</h2> R is a free software environment for statistical computing and graphics. It compiles and runs on a variety of UNIX platforms, Windows, and MacOS. It supports a wide range of packages that implement a variety of algorithms and tools for data scientists, data analysts, data engineers, statisticians, and business analysts. <h2 id="anchor-2">RStudio IDE</h2> RStudio is a free and open-source IDE (Integrated Development Environment) for R. RStudio’s GUI (Graphical User Interface) makes it easy for a coder to navigate various parts of a project like viewing graphs, data tables, R code, and output simultaneously. The developer can manage git, database connections, files and directories, R packages, and more from within RStudio. With RStudio, one can also publish a shiny dashboard to the web on shinyapps or RStudio Connect. While the IDE is already intuitive and easy to use, becoming an expert in RStudio will greatly improve the speed and efficiency of your software development. Here, we look at five tips that will make your day-to-day development tasks more efficient. <blockquote><strong>Appsilon is a proud <a href="https://appsilon.com/appsilon-data-science-is-now-an-rstudio-full-service-certified-partner/" target="_blank" rel="noopener noreferrer">RStudio Full Service Partner</a>. Discover how we can help you succeed with R and RStudio. </strong></blockquote> <h3 id="anchor-3">1) Shortcuts</h3> In day-to-day programming, we repeatedly execute several actions (e.g., restarting the R session, creating a function, or running an R Shiny application). While there are GUI elements to perform these tasks, it can be more convenient and efficient to use shortcuts. Here are some of the most useful shortcuts on RStudio: <img class="aligncenter wp-image-7672 size-full" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b02034cbd83bfce97c2bc4_shortcuts-in-rstudio-v3.webp" alt="" width="1024" height="768" /> <blockquote><strong>Check out our blog more <a href="https://appsilon.com/rstudio-shortcuts-and-tips/" target="_blank" rel="noopener noreferrer">RStudio Shortcuts and Tips</a></strong></blockquote> <img class="aligncenter size-full wp-image-7663" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b02036ac45fa2b44d0d7b2_go-to-shortcuts-in-rstudio-v2.webp" alt="" width="1024" height="768" /> <h4>Usage</h4> Apart from adding comments, commenting and uncommenting shortcuts can be used as a quick way to turn on and turn off parts of the code while experimenting and iterating with the code. The various panels can be navigated with the Ctrl + <Number> shortcuts. Quickly add documents, and then when the save all documents shortcut is pressed, RStudio will prompt the user to save the new file with a name. Running the whole document can also be used as Run App for R Shiny Apps when the Run App icon is active. <h3 id="anchor-4">2) Multi-Column View</h3> RStudio has recently introduced an awesome feature. We can now have 3 additional columns (for a total of 5) to the layout of RStudio. This is helpful as we often work with multiple documents in the project. This way, we can have more than one document open, keeping all other views intact. <img class="aligncenter size-full wp-image-7644" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b020367554f052a38cb770_multicolumnarview.webp" alt="RStudio IDE column view" width="1600" height="1000" /> <b>RStudio with 5 columns</b> To add more columns to RStudio follow these steps: <ul><li style="list-style-type: none;"><ul><li style="list-style-type: none;"><ol><li style="font-weight: 400;" aria-level="1">Click on “Tools” from the menu bar at the top</li><li style="font-weight: 400;" aria-level="1">In the dropdown, click on “Global Options”</li><li style="font-weight: 400;" aria-level="1">On the pop-up, click on “Pane Layout” tab of the left sidebar</li><li style="font-weight: 400;" aria-level="1">Now “Add Columns” or “Remove Columns” as needed</li></ol></li></ul> </li> </ul> <h3 id="anchor-5">3) Finding Functions & Variables</h3> Often, we need to find where functions or variables are used. Vice-versa, we look for function and variable definitions across the entire project. RStudio has the combined ability to search within a file as well as across all files in the working directory. It is also possible to quickly open a file in the working directory by searching for filename or function name. This helps us quickly track a function or variable across multiple documents in the project. Combine the three shortcuts below to quickly trace a function or variable. <img class="aligncenter size-full wp-image-7661" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b02038ee976c4ea9923fe3_finding-functions-and-variables-in-rstudio-v2.webp" alt="" width="1024" height="768" /> <h3 id="anchor-6">4) Multi-Cursor Editing</h3> RStudio natively supports multi-cursor functionality. That means it is possible to have multiple cursors concurrently in different parts of the code and edit them all simultaneously. There are shortcuts for faster editing using this functionality. For example, when a variable change is needed but within the scope of the function or file. And a change is needed to all names of the variable within that function, including in the argument list. This is possible with the second shortcut below. <img class="aligncenter size-full wp-image-7664" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b020393be1a22524225ddb_multi-cursor-editing-in-rstudio-v2.webp" alt="" width="1024" height="768" /> <blockquote><strong>5 Tips for <a href="https://appsilon.com/write-clean-r-code/" target="_blank" rel="noopener noreferrer">Writing Clean R Code</a></strong></blockquote> <p style="text-align: center;"><b>Ctrl/Cmd + Click/Click & Drag</b></p> <img class="aligncenter size-full wp-image-7642" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0203b3558cfc06df18318_gif1_drag.gif" alt="Click and drag cursor editing" width="512" height="256" /> <p style="text-align: center;"><b>Ctrl/Cmd + Alt/Option + Shift + M</b></p> <img class="aligncenter size-full wp-image-7643" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0203cac45fa2b44d0d9fc_gif2_shiftm.gif" alt="Ctrl+alt+shift+M" width="408" height="512" /> These are very useful in code refactoring, code cleanup, tracking variables within a scope, finding & replacing variables in the scope, adding repetitive code snippets quickly, etc. <h3 id="anchor-7">5) Investigate Function Source Code & Documentation</h3> In Microsoft Excel and Google Sheets, you can press F2 to show the formula and cells involved. Similarly, in RStudio, by pressing F2 or on mac fn + F2, it is possible to dig into the source code of any function. This action permits a quick investigation of the source code of any function in our R code. Place the cursor on the function name where used. Pressing F2 (fn + F2 in mac) will open up the source code of that function. To quickly open the function documentation, we can press F1 (fn + F1 in mac), and the built-in documentation for the function will open up in the “Help” pane at the bottom right of the screen. <img class="aligncenter size-full wp-image-7662" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b0203eccf2ef0d95c546b7_function-source-code-and-doc-in-rstudio-v2.webp" alt="" width="1024" height="768" /> <h2 id="anchor-8">Summing up RStudio (Posit) Workbench Tips</h2> These useful functionalities are the little bonuses that make RStudio a great tool to pre-process and analyze data - and build algorithms, dashboards, and applications. They make it simple to manage git repositories, packages, and code, including functions and variables. It will also help in developing and iterating faster and building more durable applications and algorithms. <h2>Let’s Build Something Beautiful Together</h2> Appsilon provides innovative <strong>data</strong> <strong>analytics</strong>, <strong>machine</strong> <strong>learning</strong>, and <strong>managed services </strong>solutions for Fortune 500 companies, NGOs, and non-profit organizations. We deliver <strong>the world’s most advanced <a class="gmail-QuillHelpers-link gmail-textEditor-link" href="https://wordpress.appsilon.com/shiny" target="_blank" rel="nofollow noopener noreferrer">R Shiny</a> applications</strong>, with a unique ability to rapidly develop and scale enterprise Shiny dashboards. Our proprietary machine learning frameworks allow us to deliver <strong><a href="https://appsilon.com/computer-vision/">Computer Vision</a></strong>, <strong>NLP</strong>, and <strong>fraud detection</strong> prototypes in as little as one week. Discover our growing list of open-source R Shiny packages at <a href="https://shiny.tools/" target="_blank" rel="noopener noreferrer">shiny.tools</a>. If you find our open-source packages useful, please consider dropping a star on your favorites at our <a href="https://github.com/Appsilon" target="_blank" rel="noopener noreferrer">Github</a>. It helps let us know we’re on the right track. And if you have any comments or suggestions, swing by our feedback threads like the discussion at our new <a href="https://github.com/Appsilon/shiny.fluent" target="_blank" rel="noopener noreferrer">shiny.fluent package</a> or submit a pull request. We value the R community’s input. <a href="https://appsilon.com/shiny/" target="_blank" rel="noopener noreferrer"><img class="aligncenter size-full wp-image-7584" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b020286d8f975c0820526a_World-ClassEnterpriseShinyDashboards_city_Appsilonlogo_wht_15.webp" alt="world class enterprise Shiny dashboards" width="1914" height="880" /></a></li> </ul>