knitr

RMarkdown: How to change headline in table of contents in R Markdown?

人走茶凉 提交于 2019-12-22 03:25:00
问题 When I'm using the toc: yes command, the document contains "Content" as the headline of the table of contents. Due to the fact that I want to write this document in german, I also want to change the headline of the table of contents to the equivalent german word. Any suggestions on how to change this? 回答1: With this YAML header that includes LaTeX-Package babel, it works for me: --- title: "TOC in German" header-includes: - \usepackage[ngerman]{babel} output: pdf_document: toc: true number

Graphing matplotlib with Python code in a R Markdown document

杀马特。学长 韩版系。学妹 提交于 2019-12-22 01:48:23
问题 Is it possible to use Python matplotlib code to draw graph in RStudio? e.g. below Python matplotlib code: import numpy as np import matplotlib.pyplot as plt n = 256 X = np.linspace(-np.pi,np.pi,n,endpoint=True) Y = np.sin(2*X) plt.plot (X, Y+1, color='blue', alpha=1.00) plt.plot (X, Y-1, color='blue', alpha=1.00) plt.show() Output graph will be: Then I need to write a R Markdown to include these code and generate graph automatically after knitting the markdown. 回答1: One possible solution is

Which is the correct folder to store images used in vignettes for R packages ?

三世轮回 提交于 2019-12-22 01:26:31
问题 I am writing a vignette for my R package. I want to include a .jpg image on the .Rmd file that will generate the pdf vignette. The question is: where should I store this image? I am using the packages devtools and knitr to generate vignettes (following the advise from @hadley book link). Therefore, I have the folder vignettes in my package structure. Should I just include the file there? Or should I include the image on a new folder inside 'inst/images' , as suggested for external data used

Replace the automatic numbering of captions inrmarkdown / knitr / pdf

余生颓废 提交于 2019-12-21 21:30:58
问题 I am generating a PDF document with Rmarkdown, within which I want to manually define figure numbers . Below is an example of a chunk: ```{r chunk26, fig.cap = "Fig. 5.3 My figure caption"} plot(1, 1) ``` I use a special numbering to follow the chapters of my document. The problem is that when I knit the PDF, "Figure X:" is automatically added before each caption. As a result, my figure captions look like this example: Note I have used the following parameters in the beginning of my rmarkdown

Evaluate a Chunk based on the output format of knitr

我的梦境 提交于 2019-12-21 19:01:31
问题 I am a beginner in using Markdown (I am using it with R studio and knitr). I am struggling with a point that I hope you would be able to help me to figure it out. I would like a chunk to be evaluated only if the output_format of the rmarkdown document is pdf. In other words, the chunk option "eval" automatically set to TRUE if the knitr output was selected as "knitr PDF". Otherwise, eval = FALSE. In your view, what is the most straightforward way to do this. Many thanks in advance 回答1: Try

R: Can I include an R markdown file in a shiny ui.R file?

倾然丶 夕夏残阳落幕 提交于 2019-12-21 17:48:21
问题 I refer to the code example at http://shiny.rstudio.com/gallery/including-html-text-and-markdown-files.html. In my case I would like to include and R markdown file rather than a markdown. The following is my code for ui.R library(markdown) shinyUI(fluidPage( titlePanel("Tourist expenditure for the year 2012 in Malta"), fluidRow( column(2, checkboxGroupInput("id1", "Analyse by", c("Sex" = "1", "Age Group" = "2") )), column(6, h4('You entered'), verbatimTextOutput("oid1") ), column(4,

In knitr, no output from pander in for loop

ⅰ亾dé卋堺 提交于 2019-12-21 09:38:32
问题 Using knitr in RStudio, pander does not produce any (or correct) html output when in a for loop. Here is a minimal case, as an Rmd input file. --- title: "Untitled" output: html_document --- Testing why pander doesn't work in for loop ```{r global_options, include=FALSE} knitr::opts_chunk$set(fig.width=7, fig.height=5, echo=FALSE, warning=FALSE, message=FALSE) ``` ```{r} library(pander) r <- 1:10 print("pander at top level") pander(summary(r)) # works print("pander in for loop") for (i in 1:2

Rmarkdown - Run code and display errors in document

China☆狼群 提交于 2019-12-21 07:39:09
问题 I get an error message when running the code below which is expected - I would like this to be ran and displayed in the pdf, however the error is returned in r and the code doesn't run. {r, warning=TRUE} library(survey) debug(withReplicates.svyrep.design) I have tried warning=TRUE but this doesn't work. How can I get the error displayed in the document? 回答1: Add error=TRUE to the chunk options. That will result in the script running to completion with the error appearing in the output. 来源:

Include code from an external R script, run in, display both code and output

狂风中的少年 提交于 2019-12-21 07:14:28
问题 Is it possible to include code from an external R script in an .Rmd and simultaneously run the code, display the code, and display its results in the output .HTML file? For example, if I have x <- 1 y <- 3 z <- x + y z in external.R . In the output document I want to see the code above along with the result of z , i.e. 4. Essentially, I want the equivalent of what would happen if I copy/pasted what's above in an R chunk. So I want ```{r} some.library::some.function("external.R") ``` to be the

Suppress automatic table name and number in an .Rmd file using xtable or knitr::kable

£可爱£侵袭症+ 提交于 2019-12-21 04:22:09
问题 I'd like to name my tables from R scripts without the automatic Table 1:... prefix when using xtable() or knitr::kable() in an .Rmd file. Output is a pdf document. Here's a reproducible example from an .Rmd file: --- title: "Suppress automatic table name and number" output: pdf_document --- ```{r myirischunk, results = 'asis', tab.cap = NULL, echo = TRUE} library(xtable) print(knitr::kable(head(iris), caption = "I sure wish it would say Table 1.a")) print(knitr::kable(head(iris), caption =