Search code examples
rrstudio

coloring parentheses and curly brackets in Rstudio


I looked in the tool options of Rstudio and couldn't find a way to color either the curly brackets or the selection of curly brackets. With the dark theme that I am using is really hard to see where my closing or opening curly brackets or parentheses are located on a long script. Is there a way to color or make these blink when selected? See a pic below:

enter image description here


Solution

  • I use a custom rstudio theme called "atom One Dark". You can download it from https://github.com/tkrabel/rstudio_atom_theme/blob/master/atom.rstheme. I was able to change the colour of the highlighted brace by following these steps:

    1. Download the "atom.rstheme" text file from https://github.com/tkrabel/rstudio_atom_theme/blob/master/atom.rstheme (or any custom rstheme file; see e.g. https://github.com/mkearney/rstudiothemes)
    2. Open the file ("atom.rstheme") in a text editor
    3. Change:
    .ace_bracket {
      margin: 0 !important;
      border: 0 !important;
      background-color: rgba(128, 128, 128, 0.5);
    }
    

    to:

    .ace_bracket {
      margin: 0 !important;
      border: 0 !important;
      background-color: rgba(73, 204, 37, 0.5);
    }
    
    1. Also change:
    .ace_marker-layer .ace_bracket {
      margin: -1px 0 0 -1px;
      border: 1px solid #4B4E55
    }
    

    to:

    .ace_marker-layer .ace_bracket {
      margin: -1px 0 0 -1px;
      border: 1px solid #25c235
    }
    

    (These edits change the highlighted brace colour from grey to bright green; choose your hex code / rgb code accordingly)

    1. Then, restart R and reload the edited theme file. To do this, click on Tools> Global Options> Appearance and select a theme that isn't "One Dark", then add the 'updated' "One Dark" theme file (Tools> Global Options> Appearance> Add and select the "atom.rstheme" from the file explorer)
    2. Restart R and you have coloured highlighting, e.g.

    image.png

    If you're on macOS, your default themes are stored in /Applications/RStudio.app/Contents/Resources/resources/themes; you can also copy one of these files and make the same changes to the '.ace_bracket' parameter e.g. copy vibrant_ink.rstheme to updated_vibrant_ink.rstheme, edit the '.ace_bracket' colors in "updated_vibrant_ink.rstheme" and then add the theme as above (Tools>Global Options>Appearance>Add).

    If you're on Windows, apparently the default themes are stored at C:\Users\<your user account>\Documents\.R\rstudio\themes (re this article).