Simone Marini Simone Marini - 2 months ago 14
R Question

RMarkdown code evaluation until command

I'm using RMarkdown where I'm building my analysis. The final output will be an html document. Actually I've got a core code which will be the final document and, after the end, I've got many lines of code with chunks and sentences that at the moment are not useful, but could be included in the final document.

    Does a command exist to say to RMarkdown to evaluate the code until that point?


Not just like
eval=FALSE
for chunks (I've got also plain text), but something like
\end{document}
in TeX. I don't want just to comment plain text and put
eval=FALSE
as chunks options.

I tried to google and read in the RMarkdown documentation, but I found nothing.

Thanks everybody! And forgive me for my poor English...

CL. CL.
Answer

From the documentation of knit_exit():

Sometimes we may want to exit the knitting process early, and completely ignore the rest of the document. This function provides a mechanism to terminate knit().

Example:

Text.

```{r}
print(1)
```

More text.

```{r}
knitr::knit_exit()
```

Ignored.

```{r}
print("Ignored.")
```

Everything after knit_exit() will be ignored. This works for all output formats.

The code above produces:

enter image description here