Sublime Text 3:运行R文件

时间:2016-03-04 13:26:45

标签: r sublimetext3 sublimerepl

我想使用SublimeREPL在Sublime Text 3中运行R文件。在文件Preferences -> Browse packages... SublimeREPL\config\R\Main.sublime-menu 中,我添加了R路径("id" -> "repl_r" -> "cmd" -> "windows"

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "R",
            "id": "SublimeREPL",
            "children":
            [
                {"command": "repl_open",
                 "caption": "R",
                 "id": "repl_r",
                 "mnemonic": "R",
                 "args": {
                    "type": "subprocess",
                    "external_id": "r",
                    "additional_scopes": ["tex.latex.knitr"],
                    "encoding": {
                        "windows": "$win_cmd_encoding",
                        "linux": "utf8",
                        "osx": "utf8"
                        },
                    "soft_quit": "\nquit(save=\"no\")\n",
                    "cmd": {"linux": ["R", "--interactive", "--no-readline"],
                            "osx": ["R", "--interactive", "--no-readline"],
                            "windows": ["C:/Program Files/R/R-3.2.3/bin/x64/Rgui.exe", "--ess","--encoding=$win_cmd_encoding"]},
                    "cwd": "$file_path",
                    "extend_env": {"osx": {"PATH": "{PATH}:/usr/local/bin"},
                                   "linux": {"PATH": "{PATH}:/usr/local/bin"},
                                   "windows": {}},
                    "cmd_postfix": "\n",
                    "suppress_echo": {"osx": true,
                                      "linux": true,
                                      "windows": false},
                    "syntax": "Packages/R/R Console.tmLanguage"
                    }
                }
            ]
        }]
    }
]

然后在工具中 - >构建系统 - >新建系统 我将它添加到文件中:

{
    "target": "run_existing_window_command",
    "id": "repl_r",
    "file": "config/R/Main.sublime-menu"
}

当我运行file.R时,R程序启动并且没有任何反应。

我已经为python做了这些操作,当我启动一个file.py时,会打开一个新标签的sublime文本(名为:REPL [python])。当我运行file.R时,我想要同样的事情。

(抱歉我的英语不好)

我进行了更改但是当我运行脚本时,窗口" REPL * [r]"打开文本:R Version 3.2.3(2015-12-10)...,但脚本中写的命令没有出现

test.R

print(1+1)

我做工具 - >构建并且不显示任何内容

我说:

"windows": "windows": ["C:/Program Files/R/R-3.2.3/bin/x64/R.exe","-f","--ess","--encoding=$win_cmd_encoding"]},

我收到错误:Fatal error : Can not open file '--ess' : No such file or directory

并且

    "windows": "windows": ["C:/Program Files/R/R-3.2.3/bin/x64/Rscript.exe","--ess","--encoding=$win_cmd_encoding"]},

我也遇到了错误:

file name is missing
***Repl Closed*** 

2 个答案:

答案 0 :(得分:1)

您正在尝试运行R GUI(图形用户界面)。 SublimeREPL期望R的命令行版本,在Windows下称为Rterm.exe。只需更改该参数,您就应该在Sublime中获得一个名为REPL [r]的新标签。您也可以致电R.exe。该部分应如下所示:

"windows": [
    "C:/Program Files/R/R-3.2.3/bin/x64/R.exe",
    "--ess",
    "--encoding=$win_cmd_encoding"
]

您可能想要做出的另一项更改 - 如果您正在使用R-Box包(我强烈推荐),请将"syntax"行更改为

"syntax": "Packages/R-Box/syntax/R Extended.sublime-syntax"

我建议稍微阅读SublimeREPL。您尝试自定义的配置菜单是在 Sublime中打开R REPL 。一旦打开,您就可以使用 Tools -> SublimeREPL 下的命令将整个文件或文件片段发送到正在运行的REPL进行评估。

答案 1 :(得分:-1)

@MattDMo写的内容一般都是正确的,但特别是错误的。 Rterm.exeRcmd.exe都是过去的遗留物( R v2?)。在相对现代的 R 安装中,运行脚本的方式是Rscript.exeR.exe -f。请查看R.exe, Rcmd.exe, Rscript.exe and Rterm.exe: what's the difference?以获取更多信息

更新

您也可以查看Running R Code from Command Line (Windows)