knitr

How to generate LaTeX file without preamble in R markdown?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-08 09:01:39
问题 I have a LaTeX document that is split to multiple .tex files. I'm using R markdown to generate figures and tables. Is it possible to generate .tex file from .Rmd without preamble, so that I will be able to just use output in my document? Currently, I need to manually copy part of the output to my .tex file 回答1: Let's suppose your child document is named child.Rmd and has the following contents. ```{r pressure, echo=FALSE, dev='pdf'} plot(pressure) ``` Run knitr::knit("child.Rmd") and you get

How to speed up bookdown generation?

怎甘沉沦 提交于 2021-02-08 07:53:49
问题 I'm currently working on a book using bookdown. It uses some code snippets which take time to compile, execute and get output. I use the following commands to build HTML, PDF and EPUB files for the book: Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')" Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::pdf_book')" Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::epub_book')" So, every time the book files are generated the actual computation takes place

Render a list of highcharts in Rmarkdown

北战南征 提交于 2021-02-08 07:30:00
问题 I generate a list of highcharts objects and tabs. Then I'd like to render it into an html page. I can't figure out how to do it in a simple loop. If i do it one by one it works, but not in a for. Here is an example : --- output: html_document --- ``` {r, echo=FALSE, results='asis'} library(highcharter) out<-list(gr1=highcharts_demo(),gr2=highcharts_demo()) cat(" Column {.tabset} ----------------------------------------------------------------------- ") cat(" ###A1 " ) out[[1]] cat(" ###A2 " )

Render a list of highcharts in Rmarkdown

久未见 提交于 2021-02-08 07:29:32
问题 I generate a list of highcharts objects and tabs. Then I'd like to render it into an html page. I can't figure out how to do it in a simple loop. If i do it one by one it works, but not in a for. Here is an example : --- output: html_document --- ``` {r, echo=FALSE, results='asis'} library(highcharter) out<-list(gr1=highcharts_demo(),gr2=highcharts_demo()) cat(" Column {.tabset} ----------------------------------------------------------------------- ") cat(" ###A1 " ) out[[1]] cat(" ###A2 " )

knitr chunk in footnote with jekyll

我是研究僧i 提交于 2021-02-08 06:22:16
问题 In the kramdown markdown documentation I read that I can insert multi line footnotes by indenting the next lines in the footnote. I tried to insert a knitr chunk into the footnote like this: --- title: "test" output: html_document layout: post --- My text[^1] [^1]:This should appear in a footnote: ```{r} runif(1:10) ``` This worked when compiling the footnote directly with knitr: If I let jekyll compile it it looks differently: The code chunk is not really in the footnote. It is above it. And

Change background colour of knitr::kable headers

北战南征 提交于 2021-02-08 06:13:35
问题 I need to change the background colour of the headers of a table printed with knitr::kable. I can use kableExtra::column_spec to change the background of a whole column, but it doesn't affect the header row: library(knitr) library(kableExtra) kable(data.frame(a = 1, b = 2)) %>% column_spec(1, background = "yellow") Wanted outcome: A kable output where the header of column a has a yellow background (and the rest of the table a white background). 回答1: You can do this using cell_spec . For

Latex symbols in rmarkdown table using knitr::kable

拥有回忆 提交于 2021-02-07 20:59:37
问题 I am trying to use knitr::kable in Rmarkdown to create a table of latex equations. However, I am having difficulties getting special characters such as $\sum$ or $\hat$ to work. For example the following works: knitr::kable(head(mtcars[,c(1,2)], 10), row.names = FALSE, col.names = c("Time", "$\\delta_{m}_1$")) but when trying to include a hat or bar the following does not work: knitr::kable(head(mtcars[,c(1,2)], 10), row.names = FALSE, col.names = c("Time", "$\\hat{m}_1$")) Has anyone figured

R markdown / bookdown - how to display keywords below an abstract?

爷,独闯天下 提交于 2021-02-07 20:47:27
问题 I defined keywords in the .Rmd file, but they are not visible in the output PDF. Current Output Expected results Current .Rmd First lines of .Rmd file looks as follows: --- title: "No keywords within the output file" abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)" keywords: "keywordA, keywordB" author: "Mateusz Kędzior" output: bookdown::pdf_document2: keep_tex: true number_sections: yes

How to number table with chapter number

北城以北 提交于 2021-02-07 20:44:29
问题 I inclue and cross-referencing a table in a Rmd file, and I want to add chapter number with the table title and referencing number, like "TABLE 1.1 test", but not "TABLE 1 test". I render the file using bookdown::word_document2. Here is a minimal example: --- title: test output: bookdown::word_document2: fig_caption: yes toc: yes --- ```{r} library(knitr) ``` # Heading 1 I'm cross-referencing a table table:\@ref(tab:test). ```{r test} test <- data.frame(a = 1:6, b = 2:7) kable(test, caption =

R markdown / bookdown - how to display keywords below an abstract?

狂风中的少年 提交于 2021-02-07 20:41:41
问题 I defined keywords in the .Rmd file, but they are not visible in the output PDF. Current Output Expected results Current .Rmd First lines of .Rmd file looks as follows: --- title: "No keywords within the output file" abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)" keywords: "keywordA, keywordB" author: "Mateusz Kędzior" output: bookdown::pdf_document2: keep_tex: true number_sections: yes