Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run R Code in R Markdown file in SublimeREPL?

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.

like image 942
Clokman Avatar asked May 06 '15 16:05

Clokman


People also ask

How do I put the R code in Markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).

Does R Markdown run code?

R Markdown still runs the code in the chunk, and the results can be used by other chunks. echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures. message = FALSE prevents messages that are generated by code from appearing in the finished file.

How do I open an R Markdown file in R?

To open a new file, click File > New File > R Markdown in the RStudio menu bar. A window will pop up that helps you build the YAML frontmatter for the . Rmd file. Use the radio buttons to select the specific type of output that you wish to build.

How do you use Markdown in RStudio?

The first thing you'll do after opening RStudio is go to File » New File » R Markdown. Then a new window will pop up where you can fill out the title of your new document, the author (um, your name? 😉), and the output format. You can choose between HTML, PDF, and Word.


1 Answers

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.

like image 152
scoa Avatar answered Sep 24 '22 19:09

scoa