knitr

With knitr, preserve chunk options when purling chunks into separate files

核能气质少年 提交于 2019-12-24 01:28:11
问题 For teaching purposes, I would like to purl the chunks of my .Rnw file into separate files. This answer explains how to do it: How to purl each chunks in .Rmd file to multiple .R files using Knitr BUT the method does not preserve the chunk options. Since the chunks I have produce plots, it's important to preserve the fig.width and fig.height options. Ideally I would like a chunk that looks like this: <<plot, fig.width = 3, fig.height = 5, outwidth = '.75\\textwidth'>>= plot (1,1) @ to become

In the “Tables”-package: How to get column percentages of a subset of a variable?

房东的猫 提交于 2019-12-24 00:36:55
问题 In the table below the column named "Percent" shows the total column percent. How do I get it to show the column percent of each level of "am" within each level of "vs"? This is what I've got: This is what I'm looking for: Knitr chunk below: <<echo=FALSE,results='asis'>>= # # library(tables) # library(Hmisc) # library(Formula) ## This gives me column percentages for the total table. latex( tabular( Factor(vs)*Factor(am) ~ gear*Percent("col"), data=mtcars ) ) ## I am trying to get column

Cannot get LyX to produce two plots are not on same line when using knitr

ぐ巨炮叔叔 提交于 2019-12-23 20:30:51
问题 Knitr newbie here. Love the package, and everything is going well except that two plots don't appear side-by-side once compiled in LyX. Not sure what is going on, as I'm copying the example from the knitr graphics manual (knitr-graphics.lyx) verbatim. My LyX code (within a Figure Float): <<two-high, fig.width=3, fig.height=2.5, out.width='0.49\\linewidth'>>= plot(cars) boxplot(cars$dist,xlab='dist') @ I can't post an image, but in the compiled pdf the plots appear under each other, not side

Difference between ERT and LyX' custom knitr insets

痞子三分冷 提交于 2019-12-23 20:11:30
问题 What's the difference , if any, in terms of control, between using ERTs , as in the minimal example, and using, instead, LyX ' own Custom Insets (Chunk, S/R expression, Sweave options) for knitr ? I've replicated the "minimal" examples, using also the Options inset inside a Chunk inset, and I can see no differences. (I am still ignorant on how to use the Sweave options inset.) 回答1: There are currently only small differences. Using the chunk inset takes a bit more time, unless you set up

Knitr hook to add code before \documentclass line in tex file to avoid options clash with xcolor

巧了我就是萌 提交于 2019-12-23 18:38:45
问题 I am trying to create a pdf document using rmarkdown and knitr . I need to use the xcolor tex package with some options (eg: [table] or [svgnames] ). Whenever I try to do so either using - \usepackage[table]{xcolor} in the YAML header or in a preamble tex file mentioned under the pdf_document includes in_header: , I am getting the following error: ! LaTeX Error: Option clash for package xcolor The option clash is because, the knitr engine pdf_document is also loading the xcolor package either

Error in applying a for loop to an xtable in knitr

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 17:04:03
问题 I'm preparing a pdf using knitr that contains a table produced using xtable. I'm adding a bold typeface to certain cells in the table so I've written the following function: bold <- function(x, matrix){ x[] <- lapply(x, as.character) for (i in 1:ncol(x)) { yes <- matrix[,i] x[yes,i] <- paste('\\textbf{', x[yes,i], '}', sep = "") } print(x, sanitize.text.function = identity) } My intention is that the object 'l.mat' is a logical matrix and by changing the 1's and 0's in the matrix I can change

R markdown asis breaks valid html code

北城余情 提交于 2019-12-23 17:01:04
问题 I have a function that outputs html code that renders properly, but encasing it in a markdown document R code chunk with ´results = "asis"` fails. I trace problem back to spaces in my HTML code. I like the spaces because they make it easier to read the raw HTML file. If you would please consider installing my R package "rockchalk", you could run this and see the same. I show the problem is caused by spaces in HTML (which markdown treats as markup for code) in the following MRE. The output I

R: Knitr gives error for SQL-chunk

十年热恋 提交于 2019-12-23 16:53:51
问题 I would like to knit the output of my R-markdown, which includes a couple of SQL-chunks. However, if I start knitting, I get the error: Line 65 Error in eval(expr, envir, enclos) : object 'pp_dataset' not found Calls: <Anonymous> ... process_group.block -> call_block -> eval_lang -> eval Execution halted I have no clue what is going on, because if I just run this chunk (which starts at line 64) then it works fine. The chunk that starts at line 64 looks as follows: ```{sql, connection=con,

RMarkdown: Floating TOC and TOC at beginning

微笑、不失礼 提交于 2019-12-23 12:16:35
问题 I was wondering if it is possible to have a floating table of contents and another one at the beginning of the document. My current front-matter looks like this: --- title: "TEST" author: brettljausn date: January 15, 2018 output: html_document: toc: true toc_float: toc_collapsed: true toc_depth: 3 number_sections: true theme: lumen --- # Rest of the sample document: -------- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` # R Markdown This is an R Markdown document.

How to get headings sans serif while preserving pdf bookmark text?

て烟熏妆下的殇ゞ 提交于 2019-12-23 12:06:04
问题 In rmarkdown I want headings with sans serif font. I can achieve this with \textsf{} latex command but later in the PDF there's no bookmark text shown. I already tried ## \textsf[Heading 1]{Heading 1} but with an error as result. Anybody got an idea how to get both? MWE: --- output: pdf_document --- ## \textsf{Heading 1} Lorem ipsum dolor sit amet, sit id rebum choro euripidis, nam ei ullum tamquam scaevola, est veniam consulatu et. Duo ex utamur atomorum. His ad dicat pericula, solet