How to run R Code in R Markdown file in SublimeREP

2019-05-02 06:59发布

问题:

I would like to test code parts in my R Markdown code without leaving Sublime Text.

For instance:

Multiplying the grades with two solves the unreliability problem:
```{r}
 chisq.test(2*grades)
```

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.

However, when I try this, I get the following error from SublimeREPL:

Cannot find REPL for 'HTML.markdown.rmarkdown'

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.

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.

回答1:

From this answer :

  1. 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 (untested)
    • Windows: %APPDATA%/Sublime Text 3/Packages (untested)
  2. Add your scode to the option "additional_scopes":

    "additional_scopes": ["HTML.markdown.rmarkdown","tex.latex.knitr"],
    
  3. Save the file, close the REPL tab, restart sublime, and open a new REPL instance.