I am writing a presentation in rmarkdown and compiling to pdf using 'Knit PDF' (Beamer). The code is as following
---
title: "Title"
author: "Author"
date: 'Date'
output:
beamer_presentation:
template: default.beamer
ioslides_presentation: default
themeoptions: compress
widescreen: yes
---
```{r setup, include=FALSE}
opts_chunk$set(cache=TRUE)
```
## Slide 1
A
## Slide 2
B
But I get the following error
Error in eval(expr, envir, enclos): object 'opts_chunk not found Calls: Anno
<nymous> .... Execution halted
I have set the 'Weave Rnw files using' field to 'knitr'. Any ideas on how I might fix this error?
Adding library(knitr) to the code chunk opts_chunk fixed it
{r setup, include=FALSE}
library(knitr)
opts_chunk$set(cache=TRUE)
Related
I am trying to compile an RMarkdown file that includes the knitcitations package. I have searched SO for "knitcitations" and did not find any similar problems to my problem.
My problem is that knitcitations citet gives an error "Empty reply from server".
My smallest reproducible example is
> knitcitations::citet("https://doi.org/10.1016/B978-012088781-1/50004-2")
Error in curl::curl_fetch_memory(url, handle = handle) :
Empty reply from server
I have tried running this in plain R and RStudio and get the same error.
Try this solution:
---
title: "Untitled"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage[T1]{fontenc}
---
```{r, warning=FALSE, include=FALSE}
library(knitcitations)
library(bibtex)
````
```{r results="asis", echo = FALSE}
citet("10.1016/B978-012088781-1/50004-2")
````
Good luck in your scientific work ;)
A minimal Rmd file is given below
---
title: "Untitled"
author: "G. A"
date: ""
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(JuliaCall)
```
```{julia}
a = sqrt(2); # the semicolon inhibits printing
println(a)
```
When compiled, I get the following error message:
Julia version 1.5.0 at location C:\Users\g_ari\AppData\Local\JuliaCall\JuliaCall\julia\v1.5.0\bin will be used. Loading setup script for JuliaCall...
Then Rstudio hangs!
I have been trying to resolve this problem.
Thanking in advance for a solution.
After updating R to version 3.6.0, and re-installing the required packages, knitting Rmd documents now seems to ignore the knitr::include_url function.
The following is a minimal example, in a file named test.Rmd -
---
title: "test"
author: "Michael Dorman"
date: "May 1, 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
```{r}
knitr::include_url("https://www.wikipedia.org/")
```
```{r}
knitr::include_graphics("https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png")
```
And here is a screenshot of the output, after pressing Knit in Rstudio -
The knitr::include_url function is ignored. No <iframe> element was produced. The knitr::include_graphics function still works, so the image does appear in the output.
Thanks for reading, I appreciate any help!
I'm having a lot of trouble getting basic references to work in R Markdown. To reduce complexity from my original project, I've decided to use the bookdown example code, but I'm experiencing the same problem. Here's a link to the intro exmample code: https://github.com/rstudio/bookdown-demo/blob/master/01-intro.Rmd
When I use Knitr to HTML or PDF the file is being generated fine but the references are not working, instead the file will just containt "#ref(example)". Here is an image to show better the output (my emphasis added in red):
Direct link to image: https://i.imgur.com/2yxB5h3.png
Here is a minimal example:
---
title: "Minimal"
output:
pdf_document:
fig_caption: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Here is a reference to the plot below \#ref(fig:minGraph)
```{r minGraph, echo=FALSE, fig.cap="\\label{fig:minGraph}test"}
plot(x=1)
```
With the output appearing as such:
https://i.imgur.com/J3UECqn.png
If you want make use of the bookdown extensions in a normal rmarkdown document you can use bookdown::html_document2 and bookdown::pdf_document2 instead of rmarkdown::html_document and rmarkdown::pdf_document. Example:
---
title: "Minimal"
output:
bookdown::html_document2:
fig_caption: yes
bookdown::pdf_document2:
fig_caption: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Here is a reference to the plot below \#ref(fig:minGraph)
```{r minGraph, echo=FALSE, fig.cap="test"}
plot(x=1)
```
Looks like I was getting my syntax confused by reading the bookdown guide while using just R markdown. Thanks to Ralf for pointing me in the this direction. The correct minimal code would be like so:
---
title: "Minimal"
output:
pdf_document:
fig_caption: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Here is a reference to the plot below \ref{fig:minGraph}
```{r minGraph, echo=FALSE, fig.cap="\\label{fig:minGraph}test"}
plot(x=1)
```
I am trying to build a beamer presentation using rmarkdown. In my presentation I want to include tables using the kable, and kableExtra packages. I am having issues with this because one of the LaTex packages that kableExtra requires is already loaded by the beamer presentation with different options. This is the error message that I receive.
! LaTeX Error: Option clash for package xcolor.
I have been searching for a fix for this but have not had any luck. I have found solutions on the LaTex pages, here and here, but I do not know LaTex and I have not figured out how to apply these solutions in the rmarkdown arena. I have tried looking at the Latex templates in rmarkdown, but I do not understand it well enough to try and implement these solutions.
Any thoughts or solutions would be much appreciated. Here is just a quick sample of the .Rmd that gives the error.
---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
output:
beamer_presentation:
keep_tex: true
header-includes:
- \usepackage[table]{xcolor}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
library(kableExtra)
dt <- mtcars[1:5, 1:6]
```
## Slide with R Output
```{r cars, echo = TRUE}
kable(dt, format = "latex")
```
## Slide with Plot
```{r pressure}
plot(pressure)
```
The linked answer on the TeX stackexchange suggests adding table to the class options for the document e.g. \documentclass[a4paper,table]{article}. In order to do this in RMarkdown, you can use a classoption: line in your YAML header:
---
title: "Untitled"
author: "Author"
date: "April 28, 2018"
classoption: table
output:
beamer_presentation:
keep_tex: true
---