How to stop RStudio from rendering nb.html on save of an R Markdown document - r

RStudio renders mynotebook.nb.html file every time R Markdown document mynotebook.Rmd is saved. This process does not involve running code in chunks, so it is much faster than knitting a notebook into mynotebook.html. However, for large .Rmd documents, saving nb.html files can take a long time, and, unfortunately, it is required to wait for it to finish before one can start using the notebook again and run code in chunks.
Is there a way to configure RStudio to not to create nb.html files on save of an R Markdown document?

I've found out you can delete relevant output entry from the top section of your file. In my case it looks like:
---
title: "Document"
output:
html_notebook: default
---
Which causes creation of .nb.html on every save. If you remove the output tag, file is no longer created automatically. You can still knit to any output file from the Knit menu on the top (or press Ctrl+Shift+K for default. This will run all the chunks again, which may take a while.
You may want to consult this guide book for more information on how YAML tags work. I'm just beginning with them!

Another reason (and solution) might be, that you clicked incidentally on the "Knit on Save" button located just under the Save-to-Disk-Symbol in RStudio. This was in my case the problem. Usually you should be able to save a rmd-file without triggering the knitting process.
So - given this scenario - just uncheck the "Knit on Save" button.

Related

Output Lines get out of bounds when I knit my Rmarkdown

when trying to knit my Rmd to output it as pdf document, some of the outputs get out of bounds
example of the output that gets out of bounds:
The YAML and settings are this:
.
Also when I "knit on save", the rstudio doesn't stop the process untill i give up waiting, idk if it's because it is trying to knit a big pdf(140 pages), but when i press stop in the Render it aborts and somehow the document shows up in my files.
Although I don't show it, i have the knitr packages installed. I've tried many forms of output, the only YAML format that i can generate a pdf with is the one from the picture. Idk if there is something that could prevent the outputs to go out of bounds. Help is appreciated

Execute all R chunks of an external Rmd file from an R script

I have a .Rmd file called f1.Rmd (containing a mix of text and R chunks) and an R script called f2.R.
I would like to insert a set of R instructions in f2.R that would execute all the R chunks contained in f1.Rmd, in such a way that all variables created in f1.Rmd would be created in my current R session if I source f2.R
(similarly to what happens when clicking on "Run" -> "Run all chunks below from the Rstudio menu").
If you render the f1.Rmd file from your current environment, this should happen.
You can use rmarkdown::render() from the console or a .R script. This will create all the variables in your current environment. It will also have the side effect of making the document.
When you use the knit button in RStudio, this launches the render in a new r session as a background process.
See also the envir option for render.
See also this answer for other options. knitr: run all chunks in an Rmarkdown document
It also depends what your .Rmd is doing.

R Notebook: Include figures in report and save plots

I'm using an R Notebook and I'd like my plots to automatically save to disk when the code is run, as well as display inline.
knitr: include figures in report *and* output figures to separate files addresses this for R Markdown but the solution given doesn't work for an R Notebook. Is there a similar option for R Notebooks?
Try setting the knitr fig.path option:
knitr::opts_chunk$set(fig.path = "path/to/figures/")
Where path/to/figures/ is the path to a subdirectory where your figures will be saved. The trailing slash is necessary. This should be a relative path, either relative to the RNotebook file or to the project directory. See here::here() for a handy way to locate the project directory.
This will put each figure into that directory; figure names will be based on the chunk name (so name your chunks!)
This is what eventually worked for me (see #TCZhang 's answer to my question here):
In addition to setting the knitr chunk fig.path="figures/" option suggested by #DonJ, try setting output: html_document, or just press the dropdown next to the Preview [Notebook] button at the top and press Knit to HTML. I think the reason this isn't working is that your output is set to output: html_notebook.
I don't know why this doesn't work specifically when the doc is in R Notebook format. I would also prefer if this worked for output: html_notebook, so it might be an issue we need to open with RStudio or knitr.

spin and "Compile Report' do not convert R script to Rmd in RStudio Preview

I want to use spin() function for my R script to produce rmarkdown .Rmd file. Instead, RStudio returns .md file. This happens in RStudio Preview version 1.1.331.
My R file is from https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R. I downloaded it and put inside my working dir. I then typed spin("test.R", format = "Rmd") in the Console pane.
When I clicked enter, in the console, it showed processing file:knitr-spin.Rmd then output file: knitr-spin.md. Then knitr-spin.html and knitr-spin.mdwere visible, but there was no knitr-spin.Rmd in the working folder.
For the next try,
I clicked the Compile Report button
I chose MS Word outputs
Unfortunately, I still received a folder and an html file and no .Rmd file. Not even .md file was created.
The last time I used spin() or Compile Report was inside RStudio 1.0.153 and it worked nicely and I got .Rmd files, html and MS Word files.
What have I done wrong or I missed?
This should work:
spin("file.R", knit = FALSE) # convert to Rmd only
According to the documentation, argument spin appears to be what you're after:
precious
logical: whether intermediate files (e.g., .Rmd files when format is "Rmd")
should be preserved; default FALSE if knit == TRUE and input is a file
Next to the Knit button there's a sprocket. Click on the Advanced tab and check "Keep markdown source file".

RStudio: Disable output of a code in Source Window while writing RMarkdown Document

I recently updated my RStudio and while writing an R Markdown document in the Source Window, whenever I run a code in a chunk of the RMD, the output is shown in the source window itself in the following manner. It gets too messy when there are huge plots. Would like to disable this feature if possible and revert back to good old style of displaying output in the Console/Plot viewer window only.
Output executed and visible below the Chunk in the Source Window
Thanks
Try this in Rstudio.
Tools > Global Options > R Markdown > Uncheck: Show output inline for all R Markdown Documents.
That should disable inline code chunk output when you're editing R Markdown documents.
Does that get you what you're asking?
Looks like OP had his question answered, but if toggling "Show output line for all R Markdown Documents" has no effect, you may be dealing with the bug detailed here: Chunk output in console not always available. You'll have to uncheck that box, restart, and then select the option to "Chunk Output in Console" from the output menu before re-enabling the former setting.

Resources