Search code examples
rvisual-studio-codelatex

IDE with LaTeX and R support: Inline output in .Rmd notebooks and weaving LaTeX document with R code


I'm trying to improve my workflow when working with R and generating documentation. I've been going between TeXStudio, JupyterLab and RStudio for a while, and I'm trying to improve my workflow. TeXStudio has limited R support, and RStudio limited support for LaTeX.

VS Code has support for multiple languages, including R and LaTeX. The fact that it can run both Jupyter notebooks, R notebooks, and LaTeX, and has plugins for other languages as well, makes it seem desirable. However, I am unable to find documentation on how to configure it to work with R and LaTeX code in the same file. In addition, I am unable to configure R notebooks to allow inline code execution output.

However, I am unable to (a) set up code execution output under the code for .Rmd notebooks, and (b) I can't figure out how to weave .Rnw (R/LaTeX) documents with Sweave/knitr.

I'm trying to find an IDE that would include features like:

  • Markdown, code and code execution output in the same document
  • Auto R and LaTeX code completion
  • Automatic display of R function documentation
  • Spell check
  • Simple R console access
  • Compile .Rnw
  • Syntax highlighting for both R code and LaTeX code

I am, primarily, requesting ways to configure VS Code, or, secondly, way to configure another IDE that can meet my requirements. A tutorial on this would be much appreciated.


Solution

  • After a bit of digging around, I found that VS Code does nearly all the things I need.

    • Auto R and LaTeX code completion, Display of R function documentation in a tab in VS Code, Simple R console access, and Syntax highlighting for both R code and LaTeX code:

    The R and LaTeX Workshop extensions, will provide highlighting and autocompletion of code in both languages. By installing R, you can easily open a session in a terminal window in VS Code, and from there open documentation inside VS Code.

    • Spell check

    Code Spell Checker offers spell check for multiple languages. Install the extension and any desired dictionaries, and set the langauges you want to be included in the extension settings.

    • Compile .Rnw files

    Turns out LaTeX Workshop can actually do this by default.

    • Markdown, code and code execution output in the same document

    This is the only thing VS Code doesn't do as far as I can tell. It can compile .Rmd files, however, but the output can only be seen in the compiled PDF. I consider this less important, since I can use Jupyter notebooks instead.