VScode太占用内存了,在作为R IDE的时候,经常后台有13个R的Front-end进程,再开启浏览器,浏览器一会就崩溃了。RStudio不是轻便IDE的第一选择。比来比去,就只有Sublime Text。
必须安装的Sublime Text插件:SendCode、Terminus。
install.packages(languageserver)
ctrl+shift+p, install package
)ctrl+shift+p, SendCode: Choose Program
,选择Terminus。ctrl+shift+p, Terminus: Open Default Shell
,在打开的(标签)窗口中运行R,或Radian。CTRL+Enter
发送当前行到R命令窗口,或者Ctrl+B
编译文件。ctrl+shift+1
、ctrl+shift+2
。上面4也可以通过编辑Sendcode的配置文件实现,通过"设置->Package settings->SendCode->setting"打开配置文件,添加如下内容:
"prog": "terminus",
"r":
{
"bracketed_paste_mode": false,
"prog": "terminus",
},
第5步可以通过快捷键运行R或Radian。“设置->热键设置”(Default (Windows).sublime-keymap),添加如下2部分内容:
// Open R at current file directory
{
"keys": ["ctrl+alt+r"],
"command": "terminus_open",
"args": {
"cmd": "D:/ProgramFiles/Coding/Miniconda3/Scripts/radian.exe",
"cwd": "${file_path:${folder}}",
"pre_window_hooks": [
["set_layout", {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}],
["focus_group", {"group": 1}]
] ,
"title": "Rterm",
"tag": "r"
}
},
// Send code to Terminus
{
"keys": ["ctrl+enter"], "command": "send_code",
"context": [
{ "key": "selector",
"operator": "equal",
"operand": "source.python,source.r,source.sql" }
],
},
第一部分:快捷键ctrl+alt+r
直接进入Radian
第二部分:设置Send Code发送的快捷键为ctrl+enter
。注意这部分是通用的,只需要将"tag"加入"operand"中,如R脚本对应的是"source.r"(Python脚本对应的是"source.python",SQL脚本对应的是"source.sql")。后面不在说明本部分的配置,最后给出总的设置。
完成以上设置后,新建R脚本。如果不保存,在“工具,编译系统”中选择“R”。按快捷键ctrl+alt+r
,自动打开一个相邻的窗口和并排的窗口,并在相邻窗口中自动进入Radian。将相邻的窗口关掉,鼠标点并排窗口,按快捷键ctrl+alt+r
,自动进入Radian。在脚本中按ctrl+enter
发送当前行或选定部分的代码到Radian,全部编译快捷键ctrl+B
。
在Python中安装Radian,主要配置文件中的路径要按照自己电脑的安装设置。如果不使用Radian,上面配置中"cmd"改为Rterm.exe,即(没有加路径,因为已经在系统路径上)
"cmd": "rterm.exe",
配置为Python IDE的方式同R。也可以直接编辑配置文件实现,下面是配置文件的编辑。
“设置->热键设置”(Default (Windows).sublime-keymap),添加如下内容(注意本机ipython.exe的路径):
//Terminus窗口打开ipython
{
"keys": ["ctrl+alt+i"],
"command": "terminus_open",
"args": {
"cmd": "D:/ProgramFiles/Coding/Miniconda3/Scripts/ipython.exe",
"cwd": "${file_path:${folder}}",
"pre_window_hooks": [
["set_layout", {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}],
["focus_group", {"group": 1}]
] ,
"title": "iPython",
"tag": "python"
}
},
如果按上面完成了R的配置,Sendcode的配置文件(“设置->Package settings->SendCode->setting”)内容如下:
{
"prog": "terminus",
"r":
{
"bracketed_paste_mode": false,
"prog": "terminus",
},
"python":
{
"bracketed_paste_mode": true,
"prog": "terminus",
},
}
要添加其他语言,可以类似修改配置文件即可。
R、Python IDE的配置文件(“设置->热键设置”(Default (Windows).sublime-keymap))如下
{ "keys": ["alt+-"], "command": "insert_snippet", "args": {"contents": " <- "} },
{ "keys": ["alt+shift+down"], "command": "duplicate_line" },
// Send code to Terminus
{
"keys": ["ctrl+enter"], "command": "send_code",
"context": [
{ "key": "selector",
"operator": "equal",
"operand": "source.python,source.r,source.sql" }
],
},
// Open R at current file directory
{
"keys": ["ctrl+alt+r"],
"command": "terminus_open",
"args": {
"cmd": "D:/ProgramFiles/Coding/Miniconda3/Scripts/radian.exe",
"cwd": "${file_path:${folder}}",
"pre_window_hooks": [
["set_layout", {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}],
["focus_group", {"group": 1}]
] ,
"title": "Rterm",
"tag": "r"
}
},
//Terminus窗口打开ipython
{
"keys": ["ctrl+alt+i"],
"command": "terminus_open",
"args": {
"cmd": "D:/ProgramFiles/Coding/Miniconda3/Scripts/ipython.exe",
"cwd": "${file_path:${folder}}",
"pre_window_hooks": [
["set_layout", {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}],
["focus_group", {"group": 1}]
] ,
"title": "iPython",
"tag": "python"
}
},
Send Code 设置(SendCode.sublime-settings)(“设置->Package settings->SendCode->setting”)如下:
{
"prog": "terminus",
"r":
{
"bracketed_paste_mode": false,
"prog": "terminus",
},
"python":
{
"bracketed_paste_mode": true,
"prog": "terminus",
},
}