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

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.

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.

Related

Is there a way to create an R knitr program file which is also an R (console) program file?

I've started using knitr (without pander) and I'm very impressed.
I can find instructions for writing inline knitr markdown – which will be processed even though a hash is written at the beginning of a line (which will be useful). However, it has occurred to me that if knitr can read and process such information, perhaps there is a way to write ALL markdown instructions e.g. ```{r} with a hash at the beginning of the line ? I.e., I would like it if ##```{r} also worked when run via knit.
This would allow me to create files which work without errors when run using R console and also when run via knit – which might be useful when files are submitted for review.

Execution of Rcpp chunks in RStudio

The knitr language engines makes it possible to include an Rcpp chunk in your R Markdown document. This works perfectly when knitting the entire document.
However, it doesn't seem to be possible to execute (that is, compile) the Rcpp chunk interactively in RStudio (v. 1.1.364), or am I missing something?
I could keep the C++ code in a separate file and use sourceCpp in a chunk, which also works fine. However, for small examples I use in teaching it's more convenient to have everything in one document. I could then use cppFunction, but that doesn't give proper syntax highlighting.
I'm either looking for an answer that shows that I, indeed, missed how to interactively compile Rcpp chunks in RStudio, or answers that suggest good practices for i) having all code in one file, and ii) being able to execute chunks interactively.

How to use inline code in markdown in Jupyter with R

How to use inline code in markdown in Jupyter with R?
CODE CELL
n <- 8
MARKDOWN CELL
The Number is {{n}}
What would be the correct syntax in Jupyter Markdown for R? Is it even possible?
In case you haven't done it already, you might want to give the python markdown extension a shot, that adds the markdown inline code functionality for Python to Jupyter notebooks. On their github they claim:
The Python Markdown extension allows displaying output produced by the current kernel in markdown cells. The extension is basically agnostic to the kernel language, however most testing has been done using Python.
Installation instructions are on the github page of the nbextensions. Make sure you'll enable the python markdown extension using a jupyter command or the extension configurator.
Calling variables then should work inside a markdown cell with the {{var-name}} syntax that you've already given (described in the readme of the corresponding github page (linked in the wiki)).
If this doesn't help, you might want to join the discussion of the corresponding issues in the issue trackers for ipython and jupyter.

Syntax highlight in R Sweave

I am fairly new to doing report with R Sweave and know the very basic applications of Latex. And I have been asked to produce some statistical reports. The R markdown is great and simple, and by default it has really nice syntax frame and grey background and syntax highlights, however, it is quite limited in terms of other type setting, not really optimal when you want to produce lengthy reports. Then I am switching to use R Sweave in R studio.
I basically want the same after-effect similar to R markdown in the Sweave. What are the easiest ways to do it? I have previously read the following post discussing:
Sweave syntax highlighting in output. And I have tried reading those package pdf, but have no clues what they are talking about, as they seem to assume readers have prior knowledges about the rendering process.
i have checked them out, but I seem to get stuck in making it to work. Can anyone tell me step by step on how to set it up (such as what to include in preamble), if possible can you kindly upload a simple Rnw file with a demonstration?
Thank!
If you use knitr rather than Sweave, you'll get syntax highlighting. It's probably possible to do it in Sweave, but knitr makes it easier.
Go to your Tools | Global Options | Sweave menu (or the similar one in Project Options) in RStudio, and choose to Weave Rnw files using knitr.
The two systems are very similar, but knitr is generally preferable these days.

Compiling *.Rnw files with knitr --without Rstudio

I would like to use knitr to create presentations that embed R objects and code.
For IT reasons I am restricted to vim, so i have found the available Rstudio+knitr examples fairly unhelpful. The vim section of the knitr documents is also very skinny, and therefore unhelpful.
Is someone able to provide some guidance on how to compile a *.Rnw or *.Rmd file using knitr (or alternately point me to a decent online tutorial?) using some combination of vim, R, and the command line?
thanks in advance
Instead of going through Rstudio, you can use the functions in the knitr package directly. There are some options you can tweak, but to get started, all you have to do is call the knit() function on your .Rnw file:
library(knitr)
knit('my_input.Rnw')
If you're missing some of Rstudio's features, it's worth remembering that most of them are just making use of things that are already available in various R packages, so you can usually find a way to use them when you don't have Rstudio available.

Resources