I am working within RStudio 1.1.383 using rmarkdown. I am trying to render to Latex a string that is created within a knitr chunk so that it appears as latex code within the document.
So far I have experimented with the 'results=' options in the chunk header and find that results='asis' enables it to be rendered once the document is knitted, but I have not been able to find a way to enable the result to be rendered using the preview feature that allows you to run a single chunk and see the results within the .Rmd editor.
Any help on this matter would be appreciated.
A minimal example is included below that should be copied into a .Rmd file before rendering.
Thanks in advance,
Michael
---
title: "Minimal Example"
output: html_document
---
```{r}
str <- "$$\\alpha \\cdot \\beta = \\delta$$"
# this doesn't show in the preview 'run chunk feature'
cat(str, "\n")
# neither does this
writeLines(str)
```
Related
I've been trying to solve some HTML knitting issues. My HTML does not currently allow me to use HTML in the code, and thus I am unable to create tabsets.
However, while trying to solve that issue a new issue occured: My HTML output adds a clickable # behind each # Header.
I use the basic Rmarkdown format:
---
title: "Try"
output: html_document
---
/```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
/```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
## Including Plots
And then the output shows me this:
Anyway have any idea how to solve this?
This is a new feature introduced in the current development version of rmarkdown. See the NEWS file for more info. To disable this feature, you may use:
output:
html_document:
anchor_sections: false
I think the question is quite self-explanatory but for avoidance of doubt I'll explain with more detail below:
I have an R Markdown document that works well if converted to HTML or uploaded to GitHub. When converting to PDF (using Latex), the results are not so pretty. I find that the biggest problem in a Latex PDF document are line breaks. I can fix the line breaks issue on the PDF document by adding "\ " characters, but that throws my HTML document out of whack too.
Is there a way to manually add line breaks (or "space before/after paragraphs") for the PDF output only?
Thank you!
You can redefine the relevant spacings in the YAML header. \parskip controls the paragraph spacing. Code blocks are shaded using a snugshade environment from the framed package. We can also redefine the shaded environment for code blocks to have some vertical space at the start. Here's a reproducible example. Note: I also added the keep_tex parameter so you can see exactly what the generated tex file looks like, in case this is useful:
title: "test"
author: "A.N. Other"
header-includes:
- \setlength{\parskip}{\baselineskip}
- \renewenvironment{Shaded}{\vspace{\parskip}\begin{snugshade}}{\end{snugshade}}
output:
pdf_document:
keep_tex: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Once you output to HTML, you can just print the HTML webpage as PDF. that might be an easy way keep the original format
Using R markdown and trying to write a small document for the group I'm working in. I wanted to be able to print a functions description directly into the Rmarkdown document I'm writing. For example if I wanted the description for the function "cor" I would use
?cor
And this prints the description in the terminal I'm working on. Now using
print(?cor)
Or
dummy <- ?cor
print(dummy)
doesn't print the description to the Rmarkdown file, but instead again prints in inside the terminal and hangs, until the user exits at which point the RMarkdown pdf is generated. Unfortunately there is no sign of it within the pdf.
How can I make R print this to Rmardkdown and not the terminal?
What you need is the printr package. Make sure you install it before using the example Rmarkdown code below (i.e. run install.packages('printr') first), but here's an example of how to include a help file in an Rmarkdown created PDF:
---
title: "SO"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Printing Help
```{r}
library(printr)
help(sum)
```
I'm getting started with rmarkdown and knitr. In the sample document provided by RStudio, I can successfully use render() to generate an HTML file that views fine in Chrome. However, when I click on the knit button, it generates a .markdown file and then returns the following error without rendering the preview:
Error generating HTML preview for ~/path/to/file/report.rmarkdown system error 2 (The system cannot find the file specified)
I think it's getting hung up at the pandoc stage. Is it possible that RStudio is looking for pandoc in the wrong place? Pandoc was already installed at C:\Program Files (x86)\Pandoc\pandoc.exe, but RStudio installed its own instance at C:\Program Files\RStudio\bin\pandoc\pandoc.exe, so maybe it's looking in the wrong place and/or confusing settings from one with the other?
Any help would be greatly appreciated. Thanks!
And just in case, here's the RMarkdown template I'm starting with:
---
title: "Monthly Report"
author: "Kris Shaffer"
date: "February 17, 2017"
output: html_document
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
R version 3.3.2
RStudio 1.0.136
rmarkdown 1.3
knitr 1.15.1
pandoc 1.17.2 (both installations)
Turns out it was as simple as a file extension. I changed the filename from report.rmarkdown to report.Rmd. Knit works fine now.
I opened a new R Markdown file in R studio and got the default small working example.
---
title: "test"
author: "Katharina Zweig"
date: "30. Januar 2016"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax
for authoring HTML, PDF, and MS Word documents. For more details on using
R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that
includes both content as well as the output of any embedded R code chunks
within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to
prevent printing of the R code that generated the plot.
It says, you only need to press the knit button to create an HTML
containg the text, the code and the results of the code. I got some long
error logs that were hardly helpful. Neither did changing the output to
PDF and Word - same result: text was there, code was there, no results of
running the code. By producing the output, the original file vanished.
What is wrong?
When the knit button is used on a file not yet saved, it asks you under which name to save it. The file needs to be saved as an Rmd file - just give no extension and R-Studio will do it right. Then, the file does not vanish and the resulting document contains the results of the r commands. I thought it asked where to save the output and gave it the extension of the output file, i.e., either myfile.html / myfile.pdf / myfile.doc.
In the chunk option try this:
{r, results='asis'}
summary(cars)
You can also embed plots, for example:
{r, echo=FALSE, results='asis'}
plot(cars)
The results = 'asis' command should output the tables and graphs if not please let me know.