简体   繁体   English

R 未附加在 Win10 上的 VS Code 中

[英]R not attached in VS Code on Win10

I am recently switching from RStudio to VS Code.我最近从 RStudio 切换到 VS Code。 I have installed R extension in VS Code, but when I open VS Code and R terminal, R cannot be loaded.我已经在 VS Code 中安装了 R 扩展,但是当我打开 VS Code 和 R 终端时,无法加载 R。 I followed coip's method but still cannot get R loaded:我遵循了 coip 的方法,但仍然无法加载 R: 在此处输入图像描述

############################################################################## I followed coip's suggstion and R is successfully activated. ################################################# ###########################我按照coip的建议,成功激活了R。 In another of my laptop (Win), R could be activated without any issue.在我的另一台笔记本电脑(Win)中,可以毫无问题地激活 R。 But when I check the settings.json file, there is no such specification as r.rterm.windows .但是当我检查settings.json文件时,没有像r.rterm.windows这样的规范。 I want to ask why my laptop could successfuly load R in VS Code without having to include those code snippet suggested by coip?我想问一下为什么我的笔记本电脑可以在 VS Code 中成功加载 R 而不必包含 coip 建议的那些代码片段?

Below is the settings.json in my laptop:以下是我笔记本电脑中的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"
    }
}

If that is your complete settings.json , you're missing common parameters such as r.rpath.windows and the --r-binary under r.rterm.option .如果这是您的完整settings.json ,那么您将缺少常用参数,例如r.rpath.windowsr.rterm.option下的 --r --r-binary I believe adding those, with the same path to R that you currently have for r.rpath.windows should fix your issue.我相信添加这些,使用与您当前对r.rpath.windows相同的 R 路径应该可以解决您的问题。

Here is a typical setup that you can copy and paste into your JSON settings, which you can access via View > Command Palette > Preferences: Open Settings (JSON):这是一个典型的设置,您可以将其复制并粘贴到您的 JSON 设置中,您可以通过 View > Command Palette > Preferences: Open Settings (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
}

Note: some of those are just preferences (eg r.bracketedPaste ).注意:其中一些只是偏好(例如r.bracketedPaste )。

So you can try to add all of the above or some of the above, save your JSON settings, and relaunch VSCode, until the problem is fixed.因此,您可以尝试添加以上所有内容或部分内容,保存您的 JSON 设置,然后重新启动 VSCode,直到问题得到解决。

If that doesn't work, let's try setting up an integrated profile, by adding the following to your settings.json :如果这不起作用,让我们尝试通过将以下内容添加到您的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"
       ]
   },
},  

You can also try making R your default terminal by adding the following line above too:您也可以尝试通过在上面添加以下行来将 R 设为您的默认终端:

"terminal.integrated.defaultProfile.windows": "R",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM