Hi. I’m Sharon Machlis at IDG Communications, here with a very quick Episode 49 of Do More With R: Color matched parentheses in RStudio.
No matter how good you are at formatting and indenting your code, if you’ve got a long and complex task, you can start losing track of which brackets and braces belong to what. Now, what we probably ought to do is refactor the code – break it up into smaller pieces and functions. But for those of us who don’t always do that . . . well, color-matching parentheses and brackets have been an RStudio requested feature since 2017.
The code has now been added! And RStudio’s Jonathan McPherson says we can test it out in the latest RStudio daily build – pre- preview-release beta code (probably more like alpha code) – at dailies dot rstudio dot com.
I downloaded the latest version to give it a try. Here’s a basic function. If I go to Code > Rainbow parentheses, the braces and brackets and parentheses will all change color to match each other.
It might be a little difficult to see here, but all the if-else braces are in green, the opening and closing braces are in red, and so on. Let me show you this on a more complex code block.
Here, I think the color-matching makes it easier for me to see which brackets belong to what if/else conditions . . . although having two shades of green, dark and light, makes it a little less obvious than I might like. Jonathan said RStudio is looking for feedback on this feature at the RStudio community forum, so I think after I record this video, I’ll head over there and suggest considering another color palette for this.
Remember: If you want to try this out yourself, head to dailies dot rstudio dot com and download the latest daily build.
That’s it for this episode, thanks for watching! For more R tips, head to the Do More With R page at bit-dot-l-y slash do more with R, all lowercase except for the R. You can also find the Do More With R playlist on the YouTube IDG Tech Talk channel — where you can subscribe so you never miss an episode. Hope to see you next time. Stay healthy and safe