我想在 VSCode 中运行 R。我已经安装了:
当我打开一个新的 R 文件时,会打开一个新的 R 终端,并且我选择并按下运行的代码不会执行。 VSCode 说 R 解释器未附加,我无法弄清楚如何执行此操作。 当我位于 R.exe 文件所在的文件夹中时,我可以从 powershell 运行 Rscripts。例如,以下内容对我有用:
.\Rscript.exe "C:\Users\Path\to\file\first_R.r"
"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.
事实上,您可以在没有管理员访问权限的情况下设置路径(只是不是永久的) - 为了方便起见,我推荐一个
.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。