bookdown::render_book vs. rmarkdown::render_site to build all outputs - r

I've got a Bookdown book for which I'd like to build a GitBook site as well as PDF and EPUB downloads. I will use Travis to build all 3 outputs, and the PDF and EPUB will be available for download from the GitBook site.
The bookdown-demo calls bookdown::render_book once for each output in _build.sh.
However, according to the logs in RStudio, the Build Book button, when building All Formats, uses rmarkdown::render_site(encoding = 'UTF-8') to build all outputs in a single command.
I'd like to ensure what happens on my CI server is exactly what happens in my IDE, so it seems like I should have Travis call rmarkdown::render_site rather than several invocations of bookdown::render_book as is done by the bookdown-demo. However, Yihui is the expert, and he has chosen to use the latter approach.
So, my question: what is the best script to invoke on a continuous integration server like Travis when multiple outputs will be built?

In bookdown projects, they usually don't make a difference, because rmarkdown::render_site() eventually calls bookdown::render_book() to render your book. Feel free to use either way.
The only exception is when your index.Rmd does not contain the field site: bookdown::bookdown_site. In that case, rmarkdown::render_site() won't work, because it doesn't know this is supposed to be a bookdown project.
BTW, to render all output formats with bookdown::render_book(), you can use the argument output_format = 'all'.

Related

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.
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.

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.

Is it possible to directly embed a Shiny app in a bookdown document?

By "directly" I mean not by uploading the app and then using knitr::include_app, but rather entering the source code of the app itself into the Bookdown document.
Rmarkdown supports this, but neither this approach, nor this seems to work with Bookdown. (The former gives an "Error: path for html_dependency not provided" error, the latter displays an empty frame.)

Rstudio Global Changes: show chunk output in console via CLI?

How can I force RStudio (v1.1.383) to evaluate R chunks always in console (instead of inline) when working with Rmarkdown documents, using a script?
I know I can set up Output chunks in Console by clicking on it:
According to this RStudio support post I could also un-check 'Show output inline for all R Markdown document' under 'Tools -> Global Options...':
But, is there a way to do it from a command line?
The reason I ask is that, I often work on my university machines and they all restore to defaults after each reset. Each time when in class, we have to manually go thru menus.
Knowing how to do it via a console command would as useful as starting each of my classes with
rm(list=ls())
There's not currently an elegant way to do this. This preference is stored inside an internal RStudio state file, in %localappdata%\RStudio-Desktop\monitored\user-settings. If you're sufficiently motivated you can write a script which sets the rmd_chunk_output_inline preference, but it's going to be unpleasant.
One thing you can do is set the chunk output type in the YAML header, like this:
---
editor_options:
chunk_output_type: console
---
You could also use an R Markdown document template with this set up for you (maybe your script could write this out).
Finally, there's an open issue for this on RStudio's github page which you might comment on and/or vote for:
https://github.com/rstudio/rstudio/issues/1607

xelatex, luatex issues when building pdf of demo book

I can build the gitbook of the demo just fine.
If I attempt to build a pdf, the .tex file is made by pandoc, but xelatex compilation bombs. I get a message in the Build window that's incomplete.
If I manually compile in the shell, I get the following output. Short story-- it would seem that there's code somewhere, probably in pandoc, that uses
\xetex_if_engine:F and
\luatex_if_engine:TF
which apparently have been non-functional since 1-1-2017.
But I can't be the first person to try to compile a pdf since January. Any ideas?
The LaTeX log shows LaTeX2e <2011/06/27>, which is too old, and you will need to refresh your filename database (FNDB) as instructed here,

Resources