demarsylvain
demarsylvain

Reputation: 2185

rstudio color appearance, specific color for package names, front ::

I'm working with R, in RStudio, and I use to specify the package of each function in my scripts, even if the package is already loaded in the environment. I want to be sure that the code will use the filter() function from dplyr, and not from another package which has a similar named function.

For instance :

enter image description here

Question/ to make code easier to read, is there a way to play with global appearance colors, and that package names (all names before ::) are in a different color (light grey for instance) ?

Upvotes: 3

Views: 1965

Answers (2)

Gowachin
Gowachin

Reputation: 1270

Here is a complete answer, I guess will work.

Since a recent version of rstudio, you can add custom themes on rstudio (see this update blog)

From this point you can create custom themes, but it require you to know the "code" for each part of your script. After opening the inspector, I've foudn that the dplyr word before the :: is named as support. See the color used in the theme Cobalt here (custom theme editor).

Finally, once you created your own theme by modification of a previous one (creating from scratch is always a pain), you import it in rstudio (see in the first link) and apply it.

At this point you won't see any change, because you also need to check Global options > Code > Diplay > highlight R function call. This will highlight the word classified as support and as support.function. You can set both colors in the theme editor (Cobalt theme has the first one in light green and the second one in light orange).

I've not done the full process myself but I think it could work.

Upvotes: 3

Matt
Matt

Reputation: 7413

You can modify themes at this website: https://tmtheme-editor.herokuapp.com/#!/editor/local/Monokai

  • If you go to Customize Preview Code at the bottom right, you can test out the code in your image above.
  • If you change the color for variable, it seems like this makes the change you're looking for.
  • When you've customized everything to your liking, you can download your custom theme. Then you can go back to Rstudio --> Tools --> Global Options --> Appearance, and click 'Add' to add your theme.

Upvotes: 2

Related Questions