knitr

knitr fail compiling chunk with scan(dec=“,”)

我怕爱的太早我们不能终老 提交于 2019-12-11 06:53:53
问题 What I'm trying is import (copy&paste) some data from Excel with comma as decimal points by using scan(dec=",") command, but I have a problem with knitr when compiling this chunk: <<>>= conc<-scan(dec=",") 9,562445749 37,66119516 72,9103195 @ I get this error: Line 22: Unexpected ',' Thanks for your help 回答1: In this case scan() requires your to run it in an interactive fashion (e.g. it waits for a blank line to terminate input), whereas knitr / Sweave runs R code in a non-interactive fashion

knitr: Chapter name is the name of R chunk code

余生长醉 提交于 2019-12-11 06:29:23
问题 I want to use the R chunk code output as the Chapter Name but could not figured out how to do this. Below is my minimum working example. \documentclass{book} \usepackage[T1]{fontenc} \begin{document} \chapter{cat( << label=Test1, echo=FALSE, results="asis">>= 2+1 @ ) } Chapter name is the output of R chunk Code. \end{document} 回答1: This works for me << label=Test1, echo=FALSE>>= cn <- 2+1 @ \chapter*{Chapter \Sexpr{cn}} 回答2: In RMarkdown you can use the following code # `r I(1+2)` 来源: https:/

R Markdown knit fails when path includes “~” for html/pdf document but works for ioslides

China☆狼群 提交于 2019-12-11 06:21:11
问题 As of knitr 1.12, there is the function include_graphics. From ?include_graphics: The major advantage of using this function is that it is portable in the sense that it works for all document formats that knitr supports, so you do not need to think if you have to use, for example, LaTeX or Markdown syntax, to embed an external image. It seems that include_graphics() handles paths with "~" in them (shortcut to user directory) when knitting an ioslides Rmarkdown presentation, but fails when

What is the difference between knitr ```{} chunks and <<>> chunks?

試著忘記壹切 提交于 2019-12-11 06:19:52
问题 I have seen both angled brackets: <<>>= ... @ and back ticks: ```{} ... ``` used to indicate 'chunks' in the knitr documentation. What is the difference between these two? For example, can I replace the following block of code from the documentation: <<my-label, eval=TRUE, dev='png'>>= set.seed(1213) # for reproducibility x = cumsum(rnorm(100)) mean(x) # mean of x plot(x, type = 'l') # Brownian motion @ with: ```{r my-label} set.seed(1213) # for reproducibility x = cumsum(rnorm(100)) mean(x)

MathJax script issue after customizing rstudio.markdownToHTML()

江枫思渺然 提交于 2019-12-11 05:33:30
问题 With knit2html() from the knitr package, I can generate html pages that contain latex equations and R code. But on my system equations are not rendered when using RStudio's "knit html" button. It is because I have modified the way the "knit html" button works. To include a table of content on my html pages, I followed the Rstudio advice on Customize Markdown Rendering. And created an .Rprofile file at the root of the project directory that overrides default markdown rendering options. My

Conditional slides in R markdown (beamer presentation)

寵の児 提交于 2019-12-11 05:14:03
问题 Is it possible to have conditional slides in R markdown (beamer presentation)? I tried using R code chunk hacks with results = 'asis' and further tried using custom LaTeX commands but to no avail. One problem seems to be that each markdown slide delimiter actually results in the combination of both \end{frame} \begin{frame} so it is hard to conditionally exclude a slide. 来源: https://stackoverflow.com/questions/43396667/conditional-slides-in-r-markdown-beamer-presentation

Pass two set of rules for rows to xtable

北慕城南 提交于 2019-12-11 05:07:50
问题 Please consider the following MWE (variation from this answer) \documentclass[a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage{booktabs} \usepackage{colortbl, xcolor} \begin{document} <<do_table, results = "asis">>= library(xtable) mydf <- data.frame(id = 1:10, var1 = rnorm(10), var2 = runif(10)) rws <- c(1,3,5,6,7) col <- rep("\\rowcolor[gray]{0.95}", length(rws)) print(xtable(mydf), booktabs = TRUE, add.to.row = list(pos = as

Knitr hook to postprocess pdf output?

最后都变了- 提交于 2019-12-11 04:12:36
问题 I have foo.Rnw file which uses the extrafont package for generating figures with text elements that use non-standard font families. After knitr calls pdflatex on my document, I want to run extrafont::embed_fonts on the resulting foo.pdf file. I can do this manually, but is there a way to do this from within knitr? (e.g., some knitr package option I can set to automatically call extrafont::embed_fonts after it knits my file and runs it through pdflatex) 回答1: As explained in this answer, it is

knitRBootstrap: zoom options, thumbnail size, and plot size

本秂侑毒 提交于 2019-12-11 04:09:35
问题 Is it possible to change the default zoom level when using knitRBootstrap? I know in my knitRbootstrap settings I can change the thumbnail size, but that doesn't allow a lot of flexibility as there is a max value: knit_bootstrap_md(input=inputFile, output=outputFile, boot_style = 'cerulean', code_style="Google Code", chooser=NULL, thumbsize = 9, show_code=FALSE) I like the features of knitRbootsrap and prefer it over conventional knitR, but not sure the easiest way to customize image size to

xtable - background colour of added rows

白昼怎懂夜的黑 提交于 2019-12-11 04:05:41
问题 I'm trying to make a table with inserted summary rows using xtable and knitr. I'd like to have these inserted lines in a different colour. Using the add.to.row option, I've managed to either insert the lines or change the colour, but not both at the same time. The reason I'm inserting the rows within xtable, rather than ahead of time, is that I want the "total" row to be spread over two columns due to its length in my original dataset. So the required solution would have both multicolumn