knitr

Insert a logo in upper right corner of R markdown pdf document

我只是一个虾纸丫 提交于 2019-12-17 08:59:14
问题 I am getting started with R markdown and I would like to create a new report having our company image logo.png in the upper right corner of each page. Is there a way to code this in the YAML section or need this to be done in a R chunk section? 回答1: You can use the includes option in the yaml to specify a custom addition to your latex header. The yaml part would look like --- output: pdf_document: keep_tex: true includes: in_header: header.tex --- and you need to save a separate file called

generate markdown comments within for loop

狂风中的少年 提交于 2019-12-17 08:59:13
问题 I am trying to generate an HTML report, using knitr, based on an R script that has for loops. I want to generate markdown comments from the comments within the for loop, but I am not sure if it's possible. Here is simple example, this is in test.R: for (i in 1:5) { ## This is a heading for `i` #' This is a comment for `i` print(i) } Then i use spin to generate a Rmd file: spin('test.R') However, the Rmd file looks like the following. ```{r } for (i in 1:5) { ## This is a heading for `i` #'

R knitr: Possible to programmatically modify chunk labels?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 07:07:36
问题 I'm trying to use knitr to generate a report that performs the same set of analyses on different subsets of a data set. The project contains two Rmd files: the first file is a master document that sets up the workspace and the document, the second file only contains chunks that perform the analyses and generates associated figures. What I would like to do is knit the master file, which would then call the second file for each data subset and include the results in a single document. Below is

How to hold figure position with figure caption in pdf output of knitr?

此生再无相见时 提交于 2019-12-17 07:05:55
问题 I am using knitr (1.9.5 and 1.9.17) and rmarkdown (0.5.3.1), and would like to hold figure position in the pdf output. The generated pdf file is working fine when chunk option fig.pos="H" is used. However, the figure position is not hold when fig_caption: yes is set in the yaml header. How should I fix this problem? Thanks for any suggestions. EDIT: After learning the float environment of Latex. I add float package into header. \usepackage{float} But the generated tex file always use htbp in

How to convert R Markdown to HTML? I.e., What does “Knit HTML” do in Rstudio 0.96?

隐身守侯 提交于 2019-12-17 06:26:34
问题 What commands are run when pressing "Knit HTML" on an R Markdown file in Rstudio 0.96? My motivation is that I might want to run the same command when I'm in another text editing environment or I might want to combine the command in a larger makefile . 回答1: Put Sys.sleep(30) in a chunk and you will see clearly what commands are called by RStudio. Basically they are library(knitr); knit() to get the markdown file; RStudio has internal functions to convert markdown to HTML; The second step will

How to set size for local image using knitr for markdown?

不想你离开。 提交于 2019-12-17 04:10:22
问题 I have a local image that I would like to include in an .Rmd file which I will then knit and convert to HTML slides with Pandoc . Per this post, this will insert the local image : ![Image Title](path/to/your/image) Is there a way to modify this code to also set the image size? 回答1: You can also read the image using png package for example and plot it like a regular plot using grid.raster from the grid package. ```{r fig.width=1, fig.height=10,echo=FALSE} library(png) library(grid) img <-

Align environment in R Markdown which works for both docx and pdf output?

﹥>﹥吖頭↗ 提交于 2019-12-14 03:57:26
问题 QUESTION: In R Markdown, what is the right way to add a LaTeX align -like environment (with and without equation numbering) which will compile and display for both docx and pdf output? DETAIL: Option 1 below is what I'm going with. But I'd still like the option to have equation numbering and not give up that functionality when I move between docx and pdf output. This compiles and displays in both docx and pdf output. Hooray! But what if I want equation numbering? \[ \begin{aligned} AR(p): Y_i

How do I produce R package vignettes in multiple formats?

末鹿安然 提交于 2019-12-14 03:40:39
问题 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

run just code from one Rmarkdown document in another Rmarkdown document with duplicate chunk names

核能气质少年 提交于 2019-12-14 01:18:29
问题 I am writing a series of reports in Rmarkdown that build off each other. I would like to include the results from the previous report in the report I am currently working on. I have seen other questions that suggested using purl to extract R code from a Rmarkdown document and then run that, so I tried the following: ```{r read.previous, echo=FALSE} source(knitr::purl("previous.Rmd",output=tempfile(),documentation=0)) ``` But when I try to knit the current report, it fails, complaining that

Pandoc for generating html file not using RStudio

不问归期 提交于 2019-12-14 01:04:16
问题 I'd like to generate html file via script below which is a part of complex source code but I don't want to install RStudio on users machine. I'm using pandoc available at: pandoc from github and the reference for path to this pandoc file is used in Sys.setenv: "C:/Users/username/AppData/Local/Pandoc". If I use RSTUDIO_PANDOC in Sys.setenv command, everything works fine in my script below but I'm just confused if RSTUDIO_PANDOC in Sys.setenv command uses default RStudio pandoc file which I don