kmacierzanka
kmacierzanka

Reputation: 825

Automatically insert whitespace in RStudio script

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))

Upvotes: 4

Views: 863

Answers (1)

Waldi
Waldi

Reputation: 41220

Under RStudio you can select the code and type Ctrl+Shift+a in Windows & Linux or Cmd+Shift+a for macOS to trigger code reformatting, see RStudio shortcuts.

Result:

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

Upvotes: 3

Related Questions