[Tex/LaTex] Sublime Latexing and Knitr on .RNW files : Send lines to R console for evaluation

knitrrsublime-text

I am using Sublime Text 3 and the Latexing package to apply Knitr to compile .Rnw files that contain both Latex and R code. Overall, it works well in that I can compile the .Rnw files into PDFs nicely. But, I am not able to get an important piece of functionality to work as compared to what I have in .R files.

Specifically, I am not able to send small pieces of code to R without compiling whole .Rnw file. I can compile the entire .Rnw file just fine, and that will of course evaluate all of the code chunks that I have knit into the document and create the PDF. I would like to be able to send small pieces of code to be evaluated in the R console without needing to compile the entire .Rnw file. (This is essentially what you can do in R Studio, and is useful for figuring out whether the code that I am including in the .Rnw file does what I want it to do without needing to compile the entire .Rnw file each time or without needing to copy/paste it into some other running R console). When I am just editing a .R document, I can do this via Command + Enter (using the Enhanced R package for Sublime) but this also doesn't work when editing a .Rnw document. Ideally, I'd like to be able to send it via REPL to the R console right within Sublime.

Are there ways to accomplish this in Sublime that I don't know about, or are they just features that have yet to be developed?

Best Answer

I had the same question, and I managed to fix it following this recommendation at least for latextools, it may be the same for latexing. /R/Main.sublime-menu file has to be edited:

(which in Ubuntu is in: ~/.config/sublime-text-3/Packages/SublimeREPL/config/R/Main.sublime-menu)

and the additional scope has to be modified in this way:

 "additional_scopes": ["tex.latex.knitr.ing"]