knitr

Aligning Columns with knitr kable function

青春壹個敷衍的年華 提交于 2019-12-04 00:14:46
问题 I am performing a simple task: creating a table and outputting it using R Markdown to pdf as follows: library(knitr) kable(datatable,align='ccccccc', col.names = c("Copy","Sigma Est","Sigma Lower","Sigma Upper", "Lambda Est","Lambda Lower","Lambda Upper"),digits=3) Problem when I output the table, columns are not centered. Actually, for some tables they are right aligned for others - left aligned, which seems rather random to me. Question How can I control the alignment of columns with R

Rotate a table from R markdown in pdf

本秂侑毒 提交于 2019-12-03 23:17:06
I'm writing in R Markdown and have a contingency table that is quite wide. I am converting the R markdown document to a PDF using pandoc. Is it possible to rotate or shrink the table? Ideally this would be done without having to switch to LaTeX formatting. My Attempts: I've been abusing the figure options in knitr to attempt this, but whether I use kable or xtable, I haven't had any luck. Some permutations I have tried include: ```{r out.extra='angle=90', results='asis'} library(knitr) kable(iris[1:5,]) ``` ``{r size='footnotesize', results='asis'} library(knitr) kable(iris[1:5,]) ``` ```{r

How do I produce R package vignettes in multiple formats?

孤人 提交于 2019-12-03 22:29:19
I use knitr and rmarkdown to write vignettes for R packages. Thanks to the magic of pandoc it is easy to turn these documents into a variety of formats. I would like to take advantage of this by offering vignettes as both HTML and PDF. There is support from rmarkdown to specify parameters for multiple output formats in the documents metadata block. For example, I might have something like this: output: html_document: standalone: true smart: true normalize: true toc: true highlight: tango self-contained: true theme: cerulean pdf_document: toc: true highlight: tango geometry: margin=2cm

knitr: how to set package options depending on output type

*爱你&永不变心* 提交于 2019-12-03 21:14:06
问题 I am starting to use package knitr as a component in the workflow to produce HTML and PDF reports from a Markdown input file. I would like to set some knitr package options specifically tailored to the format of the output file. Currently I manually switch back and forth the following two lines: <!--roptions dev='png', fig.width=300px, fig.height=200px" --> <!--roptions dev='pdf', fig.width=5, fig.height=4 --> Is it possible to let knitr know which set of options to use based on output type,

Difference between “Compile PDF” and knit2pdf

守給你的承諾、 提交于 2019-12-03 20:56:43
问题 I have a .Rnw file that I am able to compile into a PDF using the "Compile PDF" button in RStudio (or Command+Shift+k). However, when I use knit2pdf the graphics are not created and the complete PDF is not created. Why would this happen? How do you specifically set where the images will be stored so that pdflatex can find them? Here is an example. I am aware that this question that I posted a few days ago has a similar example, but in my mind these are two different questions. This file will

Knit pdf from rmd script by clicking an executable r file

雨燕双飞 提交于 2019-12-03 20:05:22
问题 Synopsis I would like to produce a pdf file from an rmd script just by clicking a file / an icon so that my coworkers don't exhaust themselves by opening RStudio first. The question When I saw this on R-bloggers, and got it working, I thought I was approaching the perfect work flow from scripting to sharing my work by letting my coworkers execute a file and get a pdf with updated numbers as a result. However, I can't get it to work with some of the functions in the knitr library. Best case

Pretty print sql code from separate file with knitr

你离开我真会死。 提交于 2019-12-03 19:13:01
问题 Knitr produces a nice, syntax highlighted code when using a code chunk as below. ```sql SELECT column FROM table ``` Is it possible to achieve the same thing but with the sql code stored in a file? Something like: ```sql read_chunk('mycode.sql') ``` 回答1: I think you can use an inline R expression to achieve it: ```sql `r xfun::file_string('mycode.sql')` ``` 来源: https://stackoverflow.com/questions/24524594/pretty-print-sql-code-from-separate-file-with-knitr

Synchronizing two leaflet maps in R / Rmarkdown

旧巷老猫 提交于 2019-12-03 18:55:39
JS leaflet allows two maps to be synchronized . See an example of synchronized leaflet maps here . I would like to implement synchronized leaflet maps in R and more specifially in Rmarkdown/knitr . Preferably, the maps should shown next to each other horizontally (just like in the example ). Here is a minimal Rmarkdown ( .Rmd ) example of two maps I would like to sync. The solution does not have to be based on the the mapview package. Any solution is welcome really (-: --- title: "How to sync 2 leaflet maps" author: "me" date: "2 April 2016" output: html_document --- ```{r SETUP, include=FALSE

How to show code but hide output in RMarkdown?

只谈情不闲聊 提交于 2019-12-03 18:38:16
问题 I want my html file to show the code, but not the output of this chunk: ```{r echo=True, include=FALSE} fun <- function(b) { for(a in b) {print(a) return(a * a)} } y <- fun(b) ``` When I run the code, i need the print to see the progress (it is quite a long function in reality). But in the knitr file, I use the output in a further chunk, so I do not want to see it in this one (and there's no notion of progress, since the code has already been run). This echo=True, include=FALSE here does not

Conditionally include a list of child documents in RMarkdown with knitr

爱⌒轻易说出口 提交于 2019-12-03 17:50:36
问题 Given a list of child documents, how can you choose which to insert into a master document based on some criteria? In my use case, I am matching the unknown entries in one dataset to the desired entries in a second dataset. The second dataset has child documents associated with each entry. If a match is found, I want to include its associated child document. In its most basic form, this psuedo-code shows the gist of what I am trying to achieve (inspired by this question here): ```{r, eval