用于执行特定代码的 R Studio 键盘快捷键

R Studio Keyboard Shortcuts to Execute Specific Code

library(ggplot2)                        # line 1
p1 <- ggplot(mtcars, aes(disp, mpg)) +  # line 2
  geom_point()                          # line 3
                                        # line 4
ggplot(mtcars, aes(mpg, disp)) +        # line 5
  geom_point()                          # line 6
                                        # line 7
10 + 10                                 # line 8  

我知道我可以在 R Studio 中突出显示上面的代码并按键盘上的 Ctrl+Enter 以 运行 该代码。

我在 R 在线教程上看到了其他方法来执行此操作,但无法弄清楚人们是如何做到的。我通过按 Alt+Shift+K 查看了 R Studio 的快捷方式,但无法找到我要查找的内容。这是我想要的键盘快捷键:

  1. 第 2 行。将光标放在 ggplot(mtcars... 和 运行 中的 g 之前,仅将代码放在第 3 行的末尾。我该怎么做?
  2. 将光标放在第 4 行的任意位置,运行 仅放在第 5 行和第 6 行。本质上 "run the next chunk"。

你能告诉我做这两件事的键盘快捷键和步骤吗?这是假设我在 R 脚本中,而不是在 R Markdown 中(尽管如果它也存在,这个答案会很好)。

您可以使用以下键盘快捷键:

Ctrl+Alt+B 运行s 从文档开头到该行的代码。 (问题 #1)

Ctrl+Alt+T 到 运行 每个部分的代码(在您的光标所在的当前部分)。 (问题 #2)

https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts