knitr

knitr: child document in different directory

旧城冷巷雨未停 提交于 2019-12-06 10:06:26
问题 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. 回答1: 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

Adjusting R Markdown Title Position in PDF output

耗尽温柔 提交于 2019-12-06 09:53:33
问题 I am creating an R Markdown report and can´t find a way to move my title down the page. Here is a minimal example, where I would like to move the title down 5cm: --- title: "This is my title to display at 5cm below the top" output: pdf_document: includes: in_header: header.tex --- \thispagestyle{titlepage} The header.tex file include some custom styling: \usepackage{fancyhdr} \fancypagestyle{titlepage}{ \fancyfoot[LE,RO]{\thepage\ of \pageref{LastPage}} \fancyfoot[LE,LO]{Project} \fancyhead[L

Unable to knit pdf from Rmardown from Rstudio in Windows 10 PC

无人久伴 提交于 2019-12-06 08:56:09
I created a new Rmd file in the latest R and Rstudio version, and with the complete version of MiKTeX installed. In my windows 10 machine. When I tried to knit it I got the following error ! LaTeX Error: File `fancyvrb.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: ! Emergency stop. <read *> l.34 \newcommand pandoc.exe: Error producing PDF Error: pandoc document conversion failed with error 43 Además: Warning message: comando ejecutado '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS pdfprueba.utf8.md --to latex

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

我怕爱的太早我们不能终老 提交于 2019-12-06 08:34:38
问题 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

Automate RStudio processed RMarkdown?

筅森魡賤 提交于 2019-12-06 08:19:03
问题 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

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

左心房为你撑大大i 提交于 2019-12-06 07:34:05
问题 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

How to use a “R-generated” plot as a semi-transparent background in an HTML5 slide made by knitr?

风流意气都作罢 提交于 2019-12-06 07:12:16
问题 I want to add a plot to my first page of the (HTML5) slide. Can I achieve this in a dynamically way? Say, the background image will be generated by R code, rather than insert a semi-transparent PNG image. Thank you. Update : What I want is 回答1: You can use the chunk option dev.args to achieve this. You will need to size the image correctly to fit your slide. ```{r dev.args = list(bg = 'transparent')} plot(1:10, 1:10) ``` This chunk will generate a transparent png. Please read the

How to force Tikz in RMarkdown document to show cyrillic text?

梦想与她 提交于 2019-12-06 06:11:10
问题 Below is my experimental RMarkdown document (named tikz-cyrillic.Rmd ): --- title: "TikZ cyrillic test" output: pdf_document: keep_tex: yes latex_engine: xelatex dev: tikz html_document: default word_document: default --- ```{r,engine='tikz', fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg'} \begin{tikzpicture} \path (0,0) node (x) {Hello World!} (3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$}; \draw[->,blue] (x) -- (y); \draw[->,red] (x) -| node[near start,below] {мир!} (y);

How can knitr keep warning messages inside the box?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 05:50:17
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(paste("A suuuuuuuuuuuuuuuuuper", "loooooooooooong waaaaaaaaaaaaarning")) @ \end{document} The warning code

opts_current: how does it work in knitr?

故事扮演 提交于 2019-12-06 05:35:54
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? 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 (temporarily for this specific chunk). 来源: https://stackoverflow.com/questions/25776547/opts-current-how-does