Return to site

Expert Programmer Ravi Bahethi Shares Four Useful Tips for Working with R and Rstudio

Originally published on chartattack.com

R is one of the more powerful programming languages for data processing and visualization. Additionally, plenty of users rely on Rstudio’s programming environment to monitor variables and interface with information. However, even experienced programmers are unaware of hacks built into the software. Here, Ravi Bahethi, president of Terranet, Inc. and our collaborator, examines four helpful shortcuts that make coding in R and Rstudio much easier.

1. Take Advantage of Auto-complete

If you are not currently using the auto-complete tab, it is time to make use of this neglected yet essential feature. You can search everything from file names to variable names with the tab key on the keyboard. This way, there is no need to memorize a seemingly endless list of names. If you rely on naming conventions for objects/functions, this hack will prove that much more critical. As an example, if the data frames in your code begin with a couple of letters such as “d.a.”, you can type “da” and hit tab to retrieve relevant object names. The auto-complete function also works for directory locations, file locations, function arguments, and packages. 

2. Shortcuts to Enhance Code


If you do not like the look of your code, give these shortcuts a try. Press the control button and “I” on the keyboard to fix problems with line indentation. If you would like to perform a full reformat of the selected portion of code, press control in unison with the shift key and the “A” key on the keyboard.

3. Rstudio’s Dark Theme is Your Friend
 

Give Rstudio’s dark theme a try, and you will find you are that much more productive. The program’s dark theme will prove especially helpful to those who spend the vast majority of their time in front of a computer screen. Activate the dark theme, and your eyes will no longer feel nearly as strained after a long work session.

Here’s how to alter the Rstudio theme: go to tools, click global options, and click appearance. Select the dark theme you like the best. Once the dark theme is activated, you will immediately notice the screen does not strain your eyes nearly as much as the default theme.

4. Move Lines of Code With a Couple Buttons
You can quickly move lines of code down or up by pressing the Alt button in combination with the arrow up/down keys. This way, you do not have to spend your limited time cutting and pasting lines of code. Use this shortcut, and you will be able to move one active line in this manner or an entire section. If you make a mistake, press the control button in unison with the “D” key to delete the current selection or line instantaneously.
All Posts
×

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!

OK