knitr

How can knitr keep warning messages inside the box?

﹥>﹥吖頭↗ 提交于 2019-12-07 20:06:38
问题 I'm writing a tutorial using knitr and I want to show some of the warnings and errors that students might encounter. While I'm capable of nicely displaying the code chunks within the box using the tidy=TRUE option, I don't understand how to handle the display of warnings and errors. For example, if I have the following code: \documentclass{article} \begin{document} <<setupOp, include=FALSE>>= opts_chunk$set(tidy=TRUE, tidy.opts=list(blank=FALSE, width.cutoff=20)) @ <<ErrorTest>>= warning

opts_current: how does it work in knitr?

五迷三道 提交于 2019-12-07 18:29:27
问题 I am trying to set up different figure size in different chunks. I first define a global settings using: opts_chunk$set(fig.width=7, fig.height=7) Then, for the specific chunks, I use: opts_current$set(fig.width=7, fig.height=14) But the later is always neglected. So, how does opts_current really work? 回答1: For specific code chunks, put the chunk options in the chunk header, e.g. ```{r fig.width=7, fig.height=14} These are called local chunk options, which will override global chunk options

How to comment out lines with knitr::spin

拈花ヽ惹草 提交于 2019-12-07 17:47:16
问题 When using spin in package knitr , how does one simply comment things out to make them invisible to spin? roxygen style lines ( #' ) are taken as lines to appear in the report. The usual R comment # is taken as an R comment and appears in a code block. Lines that are just text, with no special character at the beginning, cause an error. Lines beginning withe the LaTeX comment % cause an error. However, plain lines that follow the start of a chunk are taken to be part of the chunk and appear

How to embed an interactive shiny plot in a pdf / presentation? (via knitR maybe)

安稳与你 提交于 2019-12-07 16:16:54
问题 As the topic implies I am looking for a way to combine interactive shiny plots with knitr´s way of producing presentations/pdfs. The following intuitive approach should make my idea comprehensible. --- title: "Test" runtime: shiny output: pdf_document --- ```{r} library(shiny) library(knitr) library(rmarkdown) sliderInput("bins", "Choose Standard Deviation:", min = 0, max = 2, value = 1, step = 0.1) sliderInput("length", "Choose Length of Process:", min = 100, max = 10000, value = 1000, step

Code folding in external files with knitr and RStudio

情到浓时终转凉″ 提交于 2019-12-07 15:59:02
问题 I can find no way to insert syntactically acceptable RStudio style folds into an external R code file that is set up for use from a knitr document. Or am I missing something. There are several ways this might be done: 1) Allow a code header such as: ## @knitr Q1 ---- or perhaps ## @knitr 'Q1' ---- 2) Fold every code chunk (this would be a change in RStudio), but this is not as general as I would ideally like. 3) Allow the inclusion of some kind of comment line in code files that would

How to knit_print flextable with loop in a rmd file

旧时模样 提交于 2019-12-07 15:56:31
I am trying to produce mutltiple tables using the flextable and kable packages. When I want to output some table iteratively, I found knit_print of flextable is not working in loop. Below is a minimal example: --- output: word_document --- ```{r} library(flextable) library(knitr) ``` ```{r} data(cars) speed<-unique(cars$speed) for (v in 1:length(speed)) { carspd<-cars[which(cars$speed==speed[v]),] tb<-regulartable(carspd) knit_print(tb) } knit_print(tb) ``` Just the last knit_print can print the result to the word_document with the .Rmd file. Now I find the difference of them in .md which is

Converting Rmarkdown to PDF without RStudio

本小妞迷上赌 提交于 2019-12-07 14:48:02
问题 I would like to convert a *.Rmd to document to PDF without rstudio being available. Current approach Current approach follows the following steps: *.Rmd document is passed to knitr : knit(input = "report.Rmd")) Obtained md is converted via pandoc: # Convert pandoc --smart --to latex \ --latex-engine pdflatex \ -s report.md \ -o report.PDF Problems This results in the following problems, the top section of the Rmarkdown document: --- title: "Report Title" author: "Person" output: pdf_document

Vertical align kable's column name

余生长醉 提交于 2019-12-07 13:56:18
问题 Suppose the next example: library(knitr) library(kableExtra) df <- data.frame(a = letters[1:10], b = 1:10) names(df) <- c("This is a looooooong title, I don't know how to handle this... Also, I'm trying to extend this title even more... This column name will be used to compute vertical space","I want to align vectically this column name") df %>% kable(format = 'latex', linesep = "", align = 'c') %>% kable_styling(full_width = T) How can align vertically the second column name? 回答1: I am not

knitr: wrapping computer output in HTML tags

非 Y 不嫁゛ 提交于 2019-12-07 13:42:12
问题 With knitr, I'm trying to get the output wrapped in a div of a particular class. For example, here's the code: ```{r} # Print the pressure data set head(pressure) ```` I want the output (but not the code) to be wrapped in a div, like <div class='myclass'> , because the class provides special control over the output. (In my case, it will display in 2 columns) I found this other question on StackOverflow, but the answer provided wraps the code and output in the div, whereas I just want the

R Markdown horizontal rule that will also work with LaTeX pdf?

試著忘記壹切 提交于 2019-12-07 12:36:52
问题 I am aware that *** is Pandoc's Markdown for a horizontal rule. This horizontal line looks good on HTML, but if I knit my Markdown into a pdf the horizontal rule only runs half the width of the pdf, and it is centered. This combination just makes the horizontal rule look plain ugly. How do I properly put a horizontal rule in my R Markdown that can render properly to both HTML and pdf? Properly == full length/full width . And while I'm at it, can I format the horizontal rule (color, thickness,