R 未附加在 Win10 上的 VS Code 中
R not attached in VS Code on Win10
我最近从 RStudio 切换到 VS Code。我已经在 VS Code 中安装了 R 扩展,但是当我打开 VS Code 和 R 终端时,无法加载 R。我遵循了 coip 的方法,但仍然无法加载 R:
########################################### #################################
我听从了 coip 的建议,R 成功激活。在我的另一台笔记本电脑 (Win) 中,可以毫无问题地激活 R。但是当我检查settings.json
文件时,没有r.rterm.windows
这样的规范。 我想问一下,为什么我的笔记本电脑可以在 VS Code 中成功加载 R,而无需包含 coip 建议的那些代码片段?
下面是我笔记本电脑中的settings.json
:
{
"workbench.colorTheme": "Default Dark+",
"python.formatting.provider": "yapf",
"security.workspace.trust.untrustedFiles": "open",
"python.defaultInterpreterPath": "C:\Users\Patrick Wen\AppData\Local\Programs\Python\Python310\python.exe",
"terminal.integrated.enableMultiLinePasteWarning": false,
"files.associations": {
"*.rmd": "markdown"
}
}
如果这是您的完整 settings.json
,则您缺少常用参数,例如 r.rpath.windows
和 r.rterm.option
下的 --r-binary
。我相信添加那些,使用与您当前 r.rpath.windows
相同的 R 路径应该可以解决您的问题。
这是一个典型的设置,您可以将其复制并粘贴到您的 JSON 设置中,您可以通过查看 > 命令面板 > 首选项访问它:打开设置 (JSON):
{
// R Options
"r.rterm.windows": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.rpath.windows": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.lsp.path": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.lsp.debug": true,
"r.lsp.diagnostics": true,
"r.alwaysUseActiveTerminal": true,
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=C:\Program Files\R\R-4.1.2\bin\R.exe"
],
"r.bracketedPaste": true,
"r.sessionWatcher": true
}
注意:其中一些只是偏好(例如 r.bracketedPaste
)。
因此您可以尝试添加以上所有或部分内容,保存您的 JSON 设置,然后重新启动 VSCode,直到问题得到解决。
如果这不起作用,让我们尝试设置一个集成的配置文件,方法是将以下内容添加到您的 settings.json
:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"R": {
"path": [
"C:\Program Files\R\R-4.1.2\bin\R.exe"
]
},
},
您也可以通过在上面添加以下行来尝试将 R 设置为默认终端:
"terminal.integrated.defaultProfile.windows": "R",
我最近从 RStudio 切换到 VS Code。我已经在 VS Code 中安装了 R 扩展,但是当我打开 VS Code 和 R 终端时,无法加载 R。我遵循了 coip 的方法,但仍然无法加载 R:
########################################### #################################
我听从了 coip 的建议,R 成功激活。在我的另一台笔记本电脑 (Win) 中,可以毫无问题地激活 R。但是当我检查settings.json
文件时,没有r.rterm.windows
这样的规范。 我想问一下,为什么我的笔记本电脑可以在 VS Code 中成功加载 R,而无需包含 coip 建议的那些代码片段?
下面是我笔记本电脑中的settings.json
:
{
"workbench.colorTheme": "Default Dark+",
"python.formatting.provider": "yapf",
"security.workspace.trust.untrustedFiles": "open",
"python.defaultInterpreterPath": "C:\Users\Patrick Wen\AppData\Local\Programs\Python\Python310\python.exe",
"terminal.integrated.enableMultiLinePasteWarning": false,
"files.associations": {
"*.rmd": "markdown"
}
}
如果这是您的完整 settings.json
,则您缺少常用参数,例如 r.rpath.windows
和 r.rterm.option
下的 --r-binary
。我相信添加那些,使用与您当前 r.rpath.windows
相同的 R 路径应该可以解决您的问题。
这是一个典型的设置,您可以将其复制并粘贴到您的 JSON 设置中,您可以通过查看 > 命令面板 > 首选项访问它:打开设置 (JSON):
{
// R Options
"r.rterm.windows": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.rpath.windows": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.lsp.path": "C:\Program Files\R\R-4.1.2\bin\R.exe",
"r.lsp.debug": true,
"r.lsp.diagnostics": true,
"r.alwaysUseActiveTerminal": true,
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=C:\Program Files\R\R-4.1.2\bin\R.exe"
],
"r.bracketedPaste": true,
"r.sessionWatcher": true
}
注意:其中一些只是偏好(例如 r.bracketedPaste
)。
因此您可以尝试添加以上所有或部分内容,保存您的 JSON 设置,然后重新启动 VSCode,直到问题得到解决。
如果这不起作用,让我们尝试设置一个集成的配置文件,方法是将以下内容添加到您的 settings.json
:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\Sysnative\cmd.exe",
"${env:windir}\System32\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"R": {
"path": [
"C:\Program Files\R\R-4.1.2\bin\R.exe"
]
},
},
您也可以通过在上面添加以下行来尝试将 R 设置为默认终端:
"terminal.integrated.defaultProfile.windows": "R",