knitr

how to add a custom htmlDependency in `bookdown::gitbook`

流过昼夜 提交于 2020-01-15 04:55:48
问题 bookdown::gitbook() adds the content of https://github.com/rstudio/bookdown/tree/master/inst/resources/gitbook as a htmltools::htmlDependency . How can I add such a custom dependency to a gitbook? The goal is to provide an easy way to add a corporate css (including images). The definition of the htmlDependency() and all the required files would reside in an R package. 回答1: The ... arguments of bookdown::gitbook() are eventually passed to rmarkdown::html_document() , which are further passed

Interleaving tables and plots in R Markdown, within loop

此生再无相见时 提交于 2020-01-14 13:29:06
问题 I have a R Markdown/knittr document that generates pairs of plots and tables. The number of pairs is variable, so I create them inside of a loop. I would like the results to be interleaved in the output: table 1, plot 1, table 2, plot 2... In the example below, all tables come first at the top of the document. I have tried various permutations of pander or kable as my table function wrapping the table function in print or leaving it bare with or without results='asis' EDIT: I found a solution

How to display math in an Rmd file on Github

我怕爱的太早我们不能终老 提交于 2020-01-14 10:38:08
问题 I created a technical report in .rmd in RStudio with much math expression. With knit to html, it worked very well. As html file cannot rendered well on GitHub repository, I changed my .rmd output to github_document (.md) file. However, when I upload the file onto GitHub, I found formulas cannot be shown correctly. They are in the latex script format. I was wondering which is a valid strategy to upload a rendered .rmd file (in RStudio) into a GitHub repository? (Not GitHub Pages). Thank you.

knitr plots, labels, and captions within one chunk

Deadly 提交于 2020-01-14 07:10:12
问题 I am producing a latex report which produces multiple plots in a dlply call. The dlply call is of course in a single chunk and in order to get labels and captions to change I am using a snippet from Steve Powell below. The approach works but it seems knitr doesnt quite format the output correctly. A simple example that demonstrates: \documentclass{article} \begin{document} <startup,echo=FALSE,results='hide',message=FALSE,tidy=FALSE,warning=FALSE,fig.keep='all',comment=NA>>= require(knitr)

Cross-referencing in rticles

隐身守侯 提交于 2020-01-13 20:37:21
问题 The bookdown offers great cross-referencing options for equations, figures, tables and sections: https://bookdown.org/yihui/bookdown/cross-references.html However, they seems to not work when I set as an output 'rticles::elsevier_article'. What are the available options for cross-referencing in rticles? 回答1: I haven't tried, but there is a possible solution here: https://bookdown.org/yihui/bookdown/a-single-document.html Particularly, specify in your YAML metadata: output: bookdown::pdf_book:

How to change table of content header in knitr?

南楼画角 提交于 2020-01-13 18:00:52
问题 I am using the following options to produce a pdf document with knitr: --- title: "Test" author: "Paulo Miramor" date: "13-07-2015" output: pdf_document toc: yes --- I would like to change the header of the table of contents (which is "Contents"), since I am producing a document in Portuguese. Is there any way to customize it? 回答1: Thanks to @Molx and @Chris in the comments I could find a solution. Solution 1 Add \renewcommand{\contentsname}{Índice} to the document so that the .Rmd header is:

R CMD check does not respect selective code evaluation in knitr code chunks

天涯浪子 提交于 2020-01-13 09:14:08
问题 I am building a package in R 3.1.0 on Windows 7 32-bit (and also on a different machine running Windows 8 64bit) and I am using knitr to write vignettes using Markdown. I am hoping to publish this package on CRAN so I am using R CMD check to check that my demos, datasets and vignettes all behave properly. I keep my vignettes as .Rmd files (rather than making them outside of the package building process and stashing them in inst/doc) because they serve as extra tests on my package and aren't

Rmarkdown's render() + knitr's spin(): How to mix code blocks and nested items

。_饼干妹妹 提交于 2020-01-13 08:53:14
问题 I'm generating html- and pdf-notebooks from R -scripts using rmarkdown 's function render() and knitr 's function spin() . Sometimes I use nested lists and mix them with code blocks. Here is an example using rmarkdown and knitr chunk options. #' (1) This is normal text. #' (a) This is normal text but indented. #+ echo = TRUE, eval = TRUE print("This is code") #' (b) This is supposed to be normal text with the same #' indentation as (a). However, it will be formatted as code. #' By this I mean

LaTeX math expression in knitr kable (Sweave)

旧巷老猫 提交于 2020-01-13 07:53:09
问题 Is it possible and how to use a LaTeX math expression in a knitr/Sweave report with kable ? In the example below, $x^2$ is rendered "as is". With xtable , for the example below, I would use the option sanitize.colnames.function = function(x) x of print.xtable . Is there such an option for kable ? \documentclass{article} \usepackage{booktabs} \begin{document} <<>>= library(knitr) dat <- mtcars[1:5,1:5] options(knitr.table.format = "latex") @ <<results='asis'>>= names(dat)[1] <- "$x^2$" kable

Tableau-like grouped table in R for markdown

心不动则不痛 提交于 2020-01-12 20:32:51
问题 I frequently find myself calculating summary statistics in R using dplyr, then writing the result to csv and loading it into Tableau to generate a table because Tableau's tables are so simple and easy. I'd much rather generate the tables directly in R. Is there an easy solution for grouped tables in R? It's very easy to generate the data I would want: library(tidyr) library(dplyr) summary_table <- iris %>% gather(measure, value, -Species) %>% separate(measure, into=c("attribute", "dimension")