在 VSCode 中运行 R - R 未附加

问题描述 投票:0回答:1

我想在 VSCode 中运行 R。我已经安装了:

  1. R 4.3.1
  2. 用于运行 R 的 VSCode 扩展

当我打开一个新的 R 文件时,会打开一个新的 R 终端,并且我选择并按下运行的代码不会执行。 VSCode 说 R 解释器未附加,我无法弄清楚如何执行此操作。 I also tried selecting the R terminal in the dropdown where powershell is 当我位于 R.exe 文件所在的文件夹中时,我可以从 powershell 运行 Rscripts。例如,以下内容对我有用:

.\Rscript.exe "C:\Users\Path\to\file\first_R.r"

我尝试过的事情

  • 重新安装扩展程序
  • 使用R端子
  • 点击连接R端子
  • 我引用了this stackoverflow另一个问题(两者都由u/coip回答,这里的问题正是我所面临的,但该解决方案对我不起作用。这两个选项都没有,即。设置
    "r.rterm.windows"
    或设置集成配置文件对我有用。

这是我现在的

settings.json
:

{
    "r.plot.defaults.colorTheme": "vscode",
    "r.rpath.windows": "C:\\Program Files\\R\\R-4.3.1\\bin\\R.exe",
    "r.rterm.windows": "C:\\Program Files\\R\\R-4.3.1\\bin\\R.exe",
    "r.alwaysUseActiveTerminal": true,
    "r.rterm.option": [
        "--no-save",
        "--no-restore",
        "--r-binary=C:\\Program Files\\R\\R-4.3.1\\bin\\R.exe"
    ],
    "files.associations": {
        "*.r": "r"
    },
    "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.3.1\\bin\\R.exe"
            ]
        },
     },  
}```

Appreciate that I don't have admin access to set PATH variable. 
r visual-studio-code path
1个回答
0
投票

事实上,您可以在没有管理员访问权限的情况下设置路径(只是不是永久的) - 为了方便起见,我推荐一个

.bat
文件:

@echo off

:: set path to R
set PATH=%PATH%;C:\your\path\to\R

code --extensions-dir "C:\.vscode" 

公平警告,我停止将 VSCode 用于 R,主要将其用于 Python(此方法有效)+ Java 脚本,因此我没有再次测试 R。

© www.soinside.com 2019 - 2024. All rights reserved.