Automatically insert whitespace in RStudio script

Viewed 308

In the same ways that lines can be correctly indented using Ctrl + I or Cmd + I, is there a shortcut to automatically insert correct whitespace in RStudio scripts?

For example, for this:

df<-data.frame(x=c(1,2,3,4,5),y=c(3,4,5,6,7))

RStudio gives information saying "expected whitespace around '<-' operator" and "expected whitespace around '=' operator". Is there a shortcut to get this:

df <- data.frame(x = c(1, 2, 3, 4, 5), y = c(3, 4, 5, 6, 7))
1 Answers

Under RStudio you can select the code and type ctrl+shift+A for code reformatting, see RStudio shortcuts.

Result:

df <- data.frame(x = c(1, 2, 3, 4, 5), y = c(3, 4, 5, 6, 7))
Related