在 RStudio 脚本中自动插入空格

Automatically insert whitespace in RStudio script

与使用 Ctrl + ICmd + I 正确缩进行的方式相同,是否有在 RStudio 脚本中自动插入正确空格的快捷方式?

例如,为此:

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

RStudio 给出的信息是 “'<-' 运算符周围的预期空格”“'=' 运算符周围的预期空格”。有没有捷径可以得到这个:

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

在 RStudio 下,您可以 select 代码并键入 ctrl+shift+A 以重新格式化代码,请参阅 RStudio shortcuts

结果:

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