R语言 vscode不使用夸托向终端发送多行命令

fcg9iug3  于 5个月前  发布在  Vscode
关注(0)|答案(2)|浏览(50)

我最近换到了夸托来用r做报告,唯一的问题是在vscode中,我不能像习惯的那样向终端发送多行代码。
在.Rmd和.R文档中,我可以使用Cmd+Enter,将光标放在连接的多行代码位的任何一行上,它就会被执行。我也可以突出显示一个部分并仅执行该部分。这两种行为都不适用于.qmd文档。
在.qmd文档中,执行这类语句的唯一方法是突出显示整个部分,或者将光标放在第一行代码的上方一行。我不能发送突出显示的部分也很烦人。

# would only execute with the cursor one line above or all highlighted
diamonds %>%
   arrange(carat)

# also does not work --> not only pipe commands
purrr::map(diamonds$carat, 
                  exp)

字符串
我的设置如下:

{
    [...]
    "r.bracketedPaste": true,
    "r.rterm.mac": "/usr/local/bin/radian",
 
    "r.lsp.debug": true,
    "r.lsp.diagnostics": true,
    "files.associations": {
        "*.Rmd": "rmd"
    },
    "quarto.mathjax.theme": "dark",
    "quarto.render.previewType": "external"
   [...] 
}


我在Mac和Ubuntu上也遇到了同样的问题,所以我想这不是系统相关的。如果有人能给我一个解决方案,那就太好了。谢谢!

qlzsbp2j

qlzsbp2j1#

您也可以在夸托中通过添加键盘快捷键来使用R扩展的命令,如下所述:

{
    "key": "ctrl+enter",
    "command": "r.runSelection",
    "when": "editorTextFocus && editorLangId == quarto || editorLangId == r"
}

字符串

oyxsuwqo

oyxsuwqo2#

作为补充,如果有人在vscode中使用带有弧度的R扩展,你只需要转到扩展设置并启用括号粘贴选项
我正在做一个R tutorial和以下代码:

plot(iris$Petal.Length, iris$Petal.Width,
  col = "#cc0000",  # Hex code for datalab.cc red
  pch = 19,         # Use solid circles for points
  main = "Iris: Petal Length vs. Petal Width",
  xlab = "Petal Length",
  ylab = "Petal Width")

字符串
正在拖

r$> plot(iris$Petal.Length, iris$Petal.Width,)

r$>   col = "#cc0000",  # Hex code for datalab.cc red
Error: unexpected ',' in "  col = "#cc0000","

r$>   pch = 19,         # Use solid circles for points
Error: unexpected ',' in "  pch = 19,"

r$>   main = "Iris: Petal Length vs. Petal Width",
Error: unexpected ',' in "  main = "Iris: Petal Length vs. Petal Width","

r$>   xlab = "Petal Length",
Error: unexpected ',' in "  xlab = "Petal Length","

r$>   ylab = "Petal Width")
Error: unexpected ')' in "  ylab = "Petal Width")"

相关问题