Questions tagged [r-markdown]

R Flavored Markdown or "R Markdown" is a markdown variant used for content-creation and/or programming documentation interleaved with R code.

R Flavored Markdown, or simply "R Markdown", is a markdown variant used for content-creation and/or programming documentation in which text content is interleaved with R code. It is a modern example of literate programming and is frequently used in R vignettes and README files where an R Markdown file (usually with file extension .Rmd) is rendered as HTML via knitr pre-processing of embedded code chunks.

More details about R Markdown can be found in:

Two R packages currently implement R Markdown rendering:

Various script editors can display R Markdown documents with syntax highlighting and render the resulting markdown and HTML documents, including:

  • RStudio, a popular R IDE
  • Rcmdr, a graphical user interface available as an R package
10493 questions
55
votes
7 answers

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

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…
Bangyou
  • 9,462
  • 16
  • 62
  • 94
54
votes
4 answers

Increase width of entire HTML Rmarkdown output

I am looking to increase the overall width of my HTML Rmarkdown output. When producing PDF documents from Rmarkdowns there is an option to set the margin in the YAML section of the Rmd (ex. geometry: margin=.5in). I am looking for something similar…
NateSully
  • 551
  • 1
  • 4
  • 7
52
votes
5 answers

Adjusting width of tables made with kable() in RMarkdown documents

Is it possible to adjust the width of columns when making tables with the kable() function in knitr? A chunk like this for a table with two columns produces a table that takes up the entire width of the document. I'd like to make the columns…
N Brouwer
  • 4,778
  • 7
  • 30
  • 35
51
votes
2 answers

Loop in R markdown

I have an R markdown document like this: The following graph shows a histogram of variable x: ```{r} hist(x) ``` I want to introduce a loop, so I can do the same thing for multiple variables. Something hypothetically like this: for i in…
Merik
  • 2,767
  • 6
  • 25
  • 41
51
votes
3 answers

Changing font in PDF produced by rmarkdown

I am producing reports using rmarkdown. When knitting a PDF --- title: "Untitled" output: pdf_document --- I would like to specify the font to be used in creating the PDF. The official documentation (see section "LaTeX Options) says I can do this.…
andrey
  • 2,029
  • 2
  • 18
  • 23
51
votes
2 answers

In RStudio/RMarkdown, how to setwd?

setwd in an Rmd file in RStudio does not appear to change the directory in subsequent chunks. Is there a way to set the working directory for good? Example: ```{r} setwd("/tmp") getwd() ``` ```{r} getwd() ``` Output: setwd("/tmp") getwd() ## [1]…
user650654
  • 5,630
  • 3
  • 41
  • 44
48
votes
3 answers

Space after every five rows in kable output (with booktabs option) in R Markdown document

I am using knitr::kable() to render tables as part of an R Markdown document (that itself is part of a bookdown project). In particular, the booktabs option (through setting the booktabs argument to equal TRUE) renders the table in a nice-looking…
Joshua Rosenberg
  • 4,014
  • 9
  • 34
  • 73
48
votes
2 answers

Figures captions and labels in knitr

I'm new to Knitr. I'm trying to make a report using r chunks, and I can't figure out how to use captions and labels to reference the figure later on. Here's an example of what I would like to do: --- title: "Plotting" author: "xx" date:…
Noosh
  • 647
  • 1
  • 6
  • 11
48
votes
8 answers

Conditionally display a block of text in R Markdown

I am using knitr to parse an R Markdown document . Is there a way to conditionally display a block of text in R Markdown depending on a variable in the environment I pass into knitr? For instance, something like: `r if(show.text) {` la la la `r…
andrew
  • 2,524
  • 2
  • 24
  • 36
47
votes
1 answer

How to get an rmarkdown vignette for R package to escape CRAN warnings on Solaris and OSX

I have a couple of R packages on CRAN that have warnings against Solaris (and sometimes OSX) that are related to pandoc not being available for the vignette build. For example, here are the ggseas results on CRAN, and the source code for the…
Peter Ellis
  • 5,694
  • 30
  • 46
47
votes
3 answers

Poor resolution in knitr using Rmd

I have a .Rmd file and I am trying to create a .docx file via the function pandoc. I want to have a figure with final resolution of 504x504 pixels (i.e., 7x7inch with 72dpi). Unfortunately, the default 72 dpi is too poor in quality, and I would…
dbarneche
  • 645
  • 1
  • 5
  • 8
46
votes
3 answers

R Markdown Bullet List with Multiple Levels

https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf The cheat sheet above lists the following syntax to generate a bulleted list in R Markdown. * is the primary solid bullet. + is a secondary hollow bullet. And - is a tertiary solid…
stackinator
  • 5,429
  • 8
  • 43
  • 84
45
votes
2 answers

How can I use spell check in Rmarkdown?

I want to write a report with Rmarkdown. However, I am a little worried about my spelling. I hope there is a package installed in my Rstudio which can automatically help me spell check. So, is there such a package or is there a way to solve this…
medfordwinter
  • 577
  • 1
  • 5
  • 6
45
votes
5 answers

What is a neat command line equivalent to RStudio's Knit HTML?

What is a neat command line equivalent to RStudio's Knit HTML? Given an .Rmd file, you can use RStudio to knit .html, .docx and .pdf files using Knitr. It would be great to shift this process completely to the command line. My approach so…
elke
  • 1,220
  • 2
  • 12
  • 24
44
votes
2 answers

How to remove warning messages in R Markdown document?

I have an R Markdown document, which takes a really long time to knit because of heavy computations. Mistakenly there are some code chunks where I forgot to put warnings=False before knitting the document. Is their any way to remove those warning…
Niranjan Agnihotri
  • 916
  • 2
  • 11
  • 19