knitr

How to remove white space above and below image in R Markdown?

依然范特西╮ 提交于 2019-12-04 16:29:19
问题 I want to export a .Rmd file primarily as a latex pdf. This is the code that I'm currently using ```{r ,fig.cap="caption",fig.env='figure', fig.width=10, fig.height=10,echo=FALSE, results='asis', warning=FALSE, strip.white=TRUE} library(png) library(grid) img <- readPNG("filepath/overview.png") grid.raster(img) ``` As you can see, I'm already using strip.white=TRUE & fig.env='figure' but they don't seem to work. The .PNG file hasn't got any (white) spacing above or below the image. I know I

Printing nice cross-tabulations in knitr

亡梦爱人 提交于 2019-12-04 16:26:46
问题 What I want is to print nice crosstabulations, either in a pdf file, or in a html file, from RStudio, using R, Markdown and knitr. I suspect I am missing something really obvious, because I cannot believe this is so hard. I make cross-tabs with either xtabs or ftable. What I want is something like a nicely printed version of the R console output. > x Col Row A B C D 15 9 7 E 13 14 9 F 8 8 17 > f Col A B C Row D 15 9 7 E 13 14 9 F 8 8 17 I've tried several different solutions, none of which

How to cache in IPython Notebook?

允我心安 提交于 2019-12-04 16:23:57
问题 Environment: Python 3 IPython 3.2 Every time I shut down a IPython notebook and re-open it, I have to re-run all the cells. But some cells involve intensive computation. By contrast, knitr in R save the results in a cache directory by default so only new code and new settings would invoke computation. I looked at ipycache but it seems to cache a cell instead of the notebook. Is there a counterpart of cache of knitr in IPython? 回答1: Can you give an example of what you are trying to do? When I

trouble finding file source in .rmd chunk when knitting .rmd from master .R file

两盒软妹~` 提交于 2019-12-04 16:23:18
Let's say I have a project directory called testknit (and I do, see github for MRE), and inside this I have several subdirectories, including scripts where I keep .R and .rmd files. In RStudio, I create a project and select this testknit directory so that when I open the project, the working directory is mypath/testknit . Inside testknit/scripts I have a master.R file. If I want to source a file called testsource1.R , which is also in testknit/scripts , I can run source("scripts/testsource1.R") from within master.R . library(knitr) getwd() # [1] "mypath/testknit" source("scripts/testsource1.R"

knitr: child document in different directory

∥☆過路亽.° 提交于 2019-12-04 15:48:45
I can use the following code for child document if it is in the same directory. <<child-demo, child=knitr-input-child.Rnw, eval=TRUE>>= @ I wonder how to use child document if it is not in the same directory of master document. Thanks in advance for your help and time. This can be considered as a bug. Now I have fixed it on GitHub . Note, however, you need to setwd() to the directory of your master document before using knit() , otherwise knit() may not be able to find a child inputdir/child.Rnw . Please see if the development version works for you. Thanks! 来源: https://stackoverflow.com

stargazer left align LaTeX table columns

一曲冷凌霜 提交于 2019-12-04 15:40:29
问题 stargazer automatically centres values within tables. How can I left align the columns? Put this code in an .Rnw file and use knitr to convert to .tex: <<load, echo=FALSE, warning=FALSE, message=FALSE>>= opts_chunk$set(eval=TRUE, echo=FALSE, warning=FALSE, message=FALSE, dpi=300) @ \documentclass[a4paper,11pt]{article} \usepackage{lipsum} % Required to insert dummy text \begin{document} \title{} \author{} \date{\today} \maketitle \section{Header} Lorem ipsum dolor sit amet, consectetur

Animated rgl graphs with knitr

。_饼干妹妹 提交于 2019-12-04 14:55:08
问题 I want to include animated rgl graphs in my .Rnw document through knitr . Here is my MWE: \documentclass{article} << label = setup, include = FALSE>>= opts_chunk$set(fig.path = 'figure/', cache = FALSE, dev = "pdf", fig.align = 'center', fig.show = 'hold', fig.width = 3, fig.height = 3, echo = TRUE, warning = FALSE, message = FALSE, size = 'footnotesize', comment=NA, results='hold') knit_hooks$set(par = function(before, options, envir){ if (before && options$fig.show!='none') par(mar = c(4, 4

knitr strange out of control behavior with figures

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:35:48
I get strange behavior with figures. In some chunks knitr generates two figures from a single plot function, and the figures generated from 'chunkname' are named 'chunkname1.pdf' and 'chunkname2.pdf'. Sometimes, the first one is just a blank figure of the same size as the second one, and sometimes it is a file which cannot be open. As a work around, I set the fig.keep='last' option. But now I would like to display two plots from a same chunk and setting fig.keep to its default value, knitr generates 3 PDF figure files with the first one a corrupted file (one which can not be open). I have

Automate RStudio processed RMarkdown?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:01:32
I have an RMarkdown file that I use to generate a nice HTML report. The problem is, I want to be able to automate it so that it can run on a headless server. As such there will be nobody there to start Rstudio and press the 'knithtml' button and it seems that Rstudio is doing a LOT of additional magic like having it's own version of pandoc, running all the necessary commands, applying css styles etc. How can I take this report and generate the same thing Rstudio is generating when I press the 'knithtml' button, but by just running an R script? Thanks. Try using rmarkdown::render("/PATH/TO/YOUR

How can I insert an image from internet to the pdf file produced by R bookdown in a smart way?

a 夏天 提交于 2019-12-04 12:13:32
As far as I know, inserting an image from internet to LaTeX is not possible. You have to download the image first, and then include it locally. With R bookdown, I do it like this: download.file('https://bookdown.org/yihui/bookdown/images/cover.jpg','cover.jpg', mode = 'wb') knitr::include_graphics('cover.jpg') It works very well for both the gitbook and pdf outputs. But I do not think it is smart. It is necessary for pdf to download the file first, but unnecessary for gitbook output. The image can be included directly to the gitbook output via: knitr::include_graphics('https://bookdown.org