knitr

RMarkdown: ! Package pdftex.def Error; online image not found?

邮差的信 提交于 2019-12-18 09:16:17
问题 I am running into a problem when trying to include a web-based image within a R Markdown PDF document. Minimal Example : --- title: "Random" output: pdf_document --- ![Benjamin Bannekat](https://octodex.github.com/images/bannekat.png) Knitting the above results in the error: ! Package pdftex.def Error: File `https://octodex.github.com/images/bannekat.pn g' not found. However, if I use the following code, the image shows up: --- title: "Random" output: html_document: default html_notebook:

Using an R variable before the code chunk in which the variable was created

邮差的信 提交于 2019-12-18 09:07:09
问题 I would like to include an R calculation in the abstract. The R calculation is at the bottom of document, so when I compile the Rnw file I get an error. Here is a minimal example: \documentclass{article} \begin{document} \begin{abstract} This paper... and we got a mean of \Sexpr{mean.data}. \end{abstract} <<>>= data <- c(1,2,3,4,5) mean.data <- mean(data) @ \end{document} 回答1: If you need the computations to appear after the abstract, you can save the result to a file, and load it in the

How to center LaTeX xtable output in full text width

自闭症网瘾萝莉.ら 提交于 2019-12-18 07:35:23
问题 I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw: \documentclass[12pt,english,nohyper]{tufte-handout} \usepackage{longtable} \usepackage{geometry} \begin{document} <<include=FALSE>>= library(ggplot2) library(xtable) @ \centerline{\Large\bf This is my Main Title} <<echo=FALSE,results='asis'>>= fname='plot1.pdf' pdf(fname,width=4

How to create R-markdown sections inside a R code chunk? With proper code display

筅森魡賤 提交于 2019-12-18 07:11:50
问题 I am currently writing on a report with rmarkdown and therefore I want to create sections inside a r code chunk. I figured out that this is possible with the help of cat() and results="asis" . My problem with this solution is, that my R code results and code isn't properly displayed as usual. For example --- title: "test" output: pdf_document --- ```{r, results='asis'} for (i in 1:10) { cat("\\section{Part:", i, "}") print(summary(lm(data=X, X1~X2)) $\alpha = `r X[1,i]`$ } ``` pretty much

Knitr inline chunk options (no evaluation) or just render highlighted code

蓝咒 提交于 2019-12-18 04:01:10
问题 I cannot find information on whether it is possible to specify options for inline chunks in knitr. I've just tried specifying them, as in the regular chunk, but this gives an error. What I need is to include R code with highlighting in a PDF, but without evaluating it. This can only happen with inline chunks due to the format of the context. Or perhaps there is another way to include highlighted code. To provide an example, I need something in the lines of: Some text about something with `r

Knitr inline chunk options (no evaluation) or just render highlighted code

耗尽温柔 提交于 2019-12-18 04:01:09
问题 I cannot find information on whether it is possible to specify options for inline chunks in knitr. I've just tried specifying them, as in the regular chunk, but this gives an error. What I need is to include R code with highlighting in a PDF, but without evaluating it. This can only happen with inline chunks due to the format of the context. Or perhaps there is another way to include highlighted code. To provide an example, I need something in the lines of: Some text about something with `r

knitr, R Markdown, and xtable: xtable tables within HTML table

夙愿已清 提交于 2019-12-18 03:39:51
问题 Suppose I want to print HTML tables using xtable, side-by-side. I tried doing this in an .Rmd file with: <table border = 1> <tr> <td> `r functionThatPrintsAnHTMLTableUsingxtable` </td> <td> `r functionThatPrintsAnotherHTMLTableUsingxtable` </td> </tr> </table> No dice. What am I doing wrong? Thanks. 回答1: I think your code will work if you put results=asis in the chunk options. <table border = 1> <tr> <td> ```{r results='asis', echo=FALSE} library(xtable) data(tli) print(xtable(tli[1:20, ])

wrap long text in kable table column

送分小仙女□ 提交于 2019-12-18 03:04:09
问题 I would like wrap long text in my kable table. Here is a simple example of a table with column text that is too long and needs to be wrapped for the table to fit on the page. --- title: "test" output: pdf_document --- ```{r setup, include=FALSE} library(knitr) ``` This is my test ```{r test, echo=FALSE} test <- data.frame(v1=c("This is a long string. This is a long string. This is a long string. This is a long string. This is a long string.", "This is a another long string. This is a another

References Truncated in Beamer Presentation prepared in Knitr/RMarkdown

♀尐吖头ヾ 提交于 2019-12-18 02:57:11
问题 I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references. I'm using a pretty typical YAML header: --- title: "Title" author: "Me" date: "February 27th, 2016" output: beamer_presentation csl: ../../apa.csl bibliography: ../../RefenceDesk.bib --- This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any

Is it possible to call external R script from R markdown (.Rmd) in RStudio?

核能气质少年 提交于 2019-12-18 01:18:08
问题 It's fairly trivial to load external R scripts as per this R Sweave example: <<external-code, cache=FALSE>>= read_chunk('foo-bar.R') @ Can the same be done for R Markdown? 回答1: Yes. Put this at the top of your R Markdown file: ```{r setup, echo=FALSE} opts_chunk$set(echo = FALSE, cache=FALSE) read_chunk('../src/your_code.R') ``` Delimit your code with the following hints for knitr (just like @yihui does in the example): ## @knitr part1 plot(c(1,2,3),c(1,2,3)) ## @knitr part2 plot(c(1,2,3),c(1