问题描述
我想在我的R Markdown代码中测试代码部分,而无需离开Sublime Text.
I would like to test code parts in my R Markdown code without leaving Sublime Text.
例如:
Multiplying the grades with two solves the unreliability problem:
```{r}
chisq.test(2*grades)
```
在上面的示例中,我想选择代码为"chisq.test(2 * grades)"的行,按我的组合键,然后将其作为R代码在SublimeREPL中运行.
In the above example, I would like to select the line that has the code "chisq.test(2*grades)", press my key combination, and have it ran in SublimeREPL as R code.
但是,当我尝试这样做时,我从SublimeREPL收到以下错误:
However, when I try this, I get the following error from SublimeREPL:
当我通过视图菜单将语法更改为"R"(而不是R Markdown)时,代码运行良好.不过,这是一种解决方法,因此不受欢迎,因为这会花费我R Markdown语法高亮显示.
When I change the syntax through view menu to "R" (rather than R Markdown), the code runs fine. This is a workaround though, and it is undesirable because it costs me R Markdown syntax highlighting.
我怀疑该解决方案只是复制粘贴了几行SublimeREPL软件包代码,然后将它们重新用于R Markdown,但我仍然无法实现任何结果.我将不胜感激.
I suspect the solution is simply copy-pasting a few lines of SublimeREPL package code and repurposing them for R Markdown, but I was unable to achieve any results yet. I'd appreciate any help.
推荐答案
来自:
-
打开文件
SublimeREPL/config/R/Main.sublime-menu
.默认位置取决于您的系统
Open the file
SublimeREPL/config/R/Main.sublime-menu
. Its default position depends on your system
- Linux:
~/.config/sublime-text-3/Packages
- Mac:
~/Library/Application Support/Sublime Text 3/Packages
(未试用) - Windows:
%APPDATA%/Sublime Text 3/Packages
(未试用)
- Linux:
~/.config/sublime-text-3/Packages
- Mac:
~/Library/Application Support/Sublime Text 3/Packages
(untested) - Windows:
%APPDATA%/Sublime Text 3/Packages
(untested)
将您的代码添加到"additional_scopes"选项中:
Add your scode to the option "additional_scopes":
"additional_scopes": ["HTML.markdown.rmarkdown","tex.latex.knitr"],
保存文件,关闭REPL选项卡,重新启动sublime,然后打开一个新的REPL实例.
Save the file, close the REPL tab, restart sublime, and open a new REPL instance.
这篇关于如何在SublimeREPL的R Markdown文件中运行R代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!