FAQ Database Discussion Community


Rmarkdown directing output file into a directory

r,rstudio,knitr,rmarkdown
I found a really nice trick (link) to a function of knitr, where you can save your output html into an output folder and under a different filename. The only thing you have to head to the header is the following: title: "analysis" author: "Me" date: "`r format(Sys.time(), '%d %B,...

How to get rmarkdown and knitr to use em-dash with .docx files?

knitr,docx,rmarkdown
I am new to using rmarkdown and knitr to produce .docx word documents. The rmarkdown reference guide states that using -- gives an en-dash, and --- gives an em-dash. If I knit my .Rmd file to HTML then the en-dashes and em-dashes are working correctly, however when knitting to a...

Knitr preamble error results in “pandoc document conversion failed with error 43”

r,latex,knitr,rmarkdown,tex
Rstudio Version 0.99.441; Windows 7 enterprise; knitr 1.10.5; MiKTex 0.4.5 r.1280 (2.9 64-bit) I have a an error on my office computer when trying to knit PDF's in Rstudio, there are no problems knitting to HTML or word. The problem may be related to updates because knitting used to work...

Capture 'output_format' from rmarkdown::render as variable

r,knitr,rmarkdown
I am using RStudio with knitr, etc, to make reproducible reports, and want to have the best versions I can for both Word documents and PDF - I prefer working with LaTeX, but the end-users tend to prefer the flexibility of editable Word documents. I have written a ifelse statement...

printing inline latex equations from variable in R, trouble with \beta

r,latex,rmarkdown
I'd like to store a string of inline latex math in an r object, then output this string so that when rmarkdown is knitted, a latex equation is output in pdf. I have an error when I include "\beta" in the string. Here's the example: --- title: "Untitled" author: "Tedward"...

Rstudio 0.98.1028 add background image only to title slide

css,r,rstudio,rmarkdown
I am attempting to create a R Presentation (.Rpres) using RStudio 0.98.1028 with a different background image on the title slide and another background image on the rest of the slides. I am able to place a custom background (foo.png) by creating a css file with this in it: body...

How to create a pdf from a Rmd file using Emacs, ESS, pandoc-mode and polymode?

emacs,knitr,rmarkdown,ess
This is an adaptation of a "classic" Rmd file that I want to knit as a pdf using Emacs (Emacs Speak Statistics) and polymode. I can't find the right commands to do that. There is little documentation about polymode. I am using Emacs Starter Kit for the Social Sciences. ---...

RMarkdown with knitr to HTML: How to hide bullets in TOC (table of contents)?

html,r,knitr,rmarkdown,toc
How can I suppress the bullet points in front of the TOC items in the created HTML file? I want to see only the headline numbers... Example Test.Rmd file: --- title: "Untitled" author: "Author" date: "01/25/2015" output: html_document: number_sections: true toc: yes toc_depth: 3 --- *Content* # Headline 1 ##...

R markdown ioslides incremental mode for code chunks

r,knitr,rmarkdown
How do you turn R code chunks to appear incrementally? For example, I put the following option in the header: --- ...other configurations... output: ioslides_presentation: incremental: true --- But the incremental mode only applies to bullets and not to the code chunks ## Slide 1 * this bullet point appears...

How to emphasize column names (header) when using pandoc in R

r,rmarkdown,pandoc,pander
I know of the emphasize.rownames argument but have not been able to find its equivalent for column names. Attempted to look into panderOptions --> header.style to no avail. Please find some test code below that emphasizes the first column but not its header. Ideally, I'd be able to specify which...

r Calculating Cronbach Alpha and representing it with Knit

r,knitr,rmarkdown
I am calculating Cronbach's Alpha for two tables using this method: AlphaA <- cronbach.alpha(DadosA[,-1:-5]) AlphaB <- cronbach.alpha(DadosB[,-1:-5]) Yes, I am removing the first five columns from my data before calculating. This is working nice and when calling them in console I am getting: >AlphaA Cronbach's alpha for the 'DadosA[, -1:-5]'...

Chart images fail to appear in Word document with RMarkdown when saving to a new location

r,rmarkdown
I am creating a complex RMarkdown document that includes some charts made in ggplot2. I run the following code: rmarkdown::render(input="U:/John/R/aa_app/output/template.Rmd") This creates a Word document called "template.docx" with no problem. However, I need to be able to specify a different file name and location for this document. So I run:...

Shiny renderPlot within Interactive Document opens a new Browser Window with dygraph

r,shiny,rmarkdown,dygraphs
I have the following RMarkdown .Rmd document. When you run the following, the sliderInput is "reactive" and adjust the smoothing appropriately; however, the plot keeps generating in a new separate browser window rather than within the document itself. Any ideas why this is happening or how to fix this behavior?...

Using booktabs with Rmarkdown

r,rmarkdown,xtable
Booktabs and xtable fail with Rmarkdown using RStudio. The Tufte template works fine, but using a standard .Rmd file fails with the error message: ! Undefined control sequence. l.133 \toprule pandoc.exe: Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 A reproducible example: --- title:...

Trying to set Knitr 'document' output hook results in code chunk line breaks being lost

r,knitr,rmarkdown
I've been reading all the documentation and examples I can find for Knitr's output hooks for editing the output of the document. I'm using Knitr to process a .Rmd file, which looks like this: [SOME_SHORTCODE_TO_BE_REPLACED] (I eventually want this to be replaced by Knitr when it parses the document) ```{r...

How to run R Code in R Markdown file in SublimeREPL?

r,sublimetext,rmarkdown,sublimerepl
I would like to test code parts in my R Markdown code without leaving Sublime Text. For instance: Multiplying the grades with two solves the unreliability problem: ```{r} chisq.test(2*grades) ``` In the above example, I would like to select the line that has the code "chisq.test(2*grades)", press my key combination,...

Use rmarkdown/knitr to hold all code until the end

r,knitr,rmarkdown,reproducible-research
I'd like to be able to generate a document using knitr/rmarkdown that keeps all the output together, but leaves the code until the end, ideally as a referenced footnote of sorts (i.e. the code for each figure or output can be looked up in the appendix using a footnote). Is...

What is the command in RMarkdown to “source” and display the code from an existing .R file?

r,rmarkdown
Example: My R script is named "code.R". It produces a simple plot of y versus x. And looks like this in Rmarkdown. ````{r eval=FALSE} ## code in "code.R" x = 1:10 y = 1:10 plot(x,y) ``` For documentation and reproducibility I want to create a Rmarkdown file which reads "code.R"...

Unexpected xtable output (in html) when formatting numbers

r,knitr,rmarkdown,xtable
In the following code, when I enable the prettyNum(formatC... command, I get the strange output that you see in the picture. The code worked OK with R 3.1.1. There is no problem when output format is pdf. --- title: "Untitled" output: html_document --- Create test data. ```{r} library(xtable) my_tab <-...

Differences in R Markdown syntax highlighting for in-line code

r,syntax-highlighting,rstudio,rmarkdown
The following minimal R Markdown file minimal.Rmd produces different minimal.html output (via "Knit HTML" in RStudio) depending on my system. The first is the result on my Windows 8 machine. The second is the result on my Windows 7 (64-bit) machine. Differences: Red syntax highlighting on in-line code in Win8...

How can I force a line break in rmarkdown's title?

r,rmarkdown
I have a quite long title in a rmarkdown document and I would like to force a line break in a specific position. Minimum example: --- title: "Quite long title want the * line break at the asterisk" output: html_document --- I have tried: \n, \newline, \\ and a manual...

Exclude part of R markdown documents based on output document type

r,knitr,rmarkdown
Is it possible to render part of an Rmarkdown document only for a specific output? For example, I would like to use the same analysis both to write a report and a presentation. I would like to be able to have some part of the document only to be rendered...

Defer code to END of document in knitr

r,knitr,rmarkdown
I am trying to write a report in rmarkdown and then use knitr to generate a pdf. I want all the code to be pushed to the "End of the document", while just displaying results interweaved with my text. The echo='hold' option doesn't do this. Section of my markdown file...

Incorrect conversion from R Markdown to LaTeX

latex,knitr,rmarkdown,pandoc
Why does the following R Markdown minimal (non)-working example not compile to PDF? --- header-includes: - \usepackage{fancyhdr} - \pagestyle{fancy} - \lhead{} - \chead{} - \rhead{The performance of new graduates} - \lfoot{From: K. Grant} - \cfoot{To: Dean A. Smith} output: pdf_document: keep_tex: yes latex_engine: xelatex --- # Test In particular, the...

Rmarkdown Slidy indented lists

html,r,rmarkdown,slidy
I use Rmarkdown with slidy mostly. I like it because I can use html tags outside of r code chunks (perhaps it is do-able in other formats, no idea). However I run into trouble with indented lists. --- title: "Test" author: "Me" date: "Today" output: slidy_presentation --- ## Test Slide...

Keep getting errors when trying to knit a PDF using R Markdown

r,rstudio,knitr,rmarkdown
cross-post from /r/RStudio Hello everybody, So I've attempted to troubleshoot this issue for about 4 hours last night with no luck. I've looked through all the similar issues in the RStudio community and attempted all the suggested "fixes", but still haven't been able to get this darn thing to work....

Are rCharts and DT compatible in rmarkdown?

r,rmarkdown,rcharts
I am trying to create a document with rmarkdown that includes both plots from the rCharts package and a datatable using the DT library included in htmlwidgets. For some reason I cannot display both of them together. --- title: "Untitled" output: html_document --- ```{r, echo=FALSE} library(DT) library(rCharts) df<-data.frame(Name=c("a","Z","h","k","j"),Value=(sample(10^7,5))) datatable(df, filter...

Edit title slide of R Markdown Slidy Presentation

rmarkdown,slidy
Is there a way to edit the title slide of a R Markdown Slidy Presentation? I am able to add the header, footer, and custom css: title: "Slidy Template" author: "" date: "June 18, 2015" runtime: shiny output: slidy_presentation: css: ./styles/Slidy_Styles.css includes: after_body: ./styles/doc_suffix.html before_body: ./styles/header.html But I can't figure...

pandoc version 1.12.3 or higher is required and was not found (R shiny)

pandoc,rmarkdown,shiny-server
I have a problem generating a pdf report from my app shiny which is hosted on a server. the app works fine but when I press the button to download the report, I get this error : pandoc version 1.12.3 or higher is required and was not found. The proble...

R read.csv from URL error in knitr

r,knitr,rmarkdown,read.table
When I run this code in the R console, it works fine: read.csv('https://courses.edx.org/c4x/MITx/15.071x_2/asset/WHO.csv') But when I try to put in into an R markdown document and knit it, I get the following: Error in open.connection(file, "rt") : cannot open the connection Calls: <Anonymous> ... eval -> read.csv -> read.table ->...

HTML page which takes the input, runs the R code and gives the result back to HTML

html,r,shiny,knitr,rmarkdown
I'm trying to design a front end to display the result of my R code which takes 2 files,master.csv and detail.csv. Master.csv contains reference data with 2 columns which contains Commodity Category and Commodity Name as shown below: Sl.No. Commodity Category Commodity Name 1 Stationary Pencil 2 Stationary Pen 3...

Evaluate a Chunk based on the output format of knitr

r,rstudio,knitr,rmarkdown
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...

Add sections to beamer presentation using rmarkdown and knitr

r,latex,markdown,knitr,rmarkdown
I am trying to add section slides to a beamer presentation written in rmarkdown using the latex command \section{}. However, it gets inserted between a \begin{frame} & \end{frame} automatically during the conversion, which causes the compilation to fail. Is there any way to stop this happening so that the section...

How to use greek letters in fig.caption using RMarkdown?

latex,rmarkdown,caption
This code produces an error when I try to knit a pdf using RMarkdown in RStudio. How can I write a greek letter in fig.caption as for example $\beta$? --- title: "Untitled" author: "SB" date: "Thursday, January 29, 2015" output: pdf_document: fig_caption: yes --- ```{r var, echo=FALSE, fig.cap="Cars variation rate...

Change background colour of rmarkdown pdf output

r,pdf,render,rstudio,rmarkdown
I am currently using RStudio 0.98.1091 and I am trying to create a pdf document with the render function from the rmarkdown package. R script: library("rmarkdown") render("input.Rmd", "pdf_document") input.Rmd --- title: "Report" output: pdf_document --- <style> body {background-color:lightgray} </style> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> I...

How to format dygraphs labels in R - comma separate thousands place?

r,shiny,rmarkdown,dygraphs
I am working with the htmlwidget dygraphs for R. My series spans a range from about 0 to 150,000. I have tried using dyOptions(labelsKMB = "K") -- this formats y-axis as 0K, 20K, 40K, ... - however, as a result, the legend is also formatted with rounded values - e.g....

How to generate a GitHub flavoured markdown file using knitr?

r,knitr,pandoc,rmarkdown,github-flavored-markdown
I love using knitr to generate dynamic reports and share them with my co-workers using GitHub. What I usually do is to knit my Rmarkdown script --knit ('myfile.Rmd')-- and generate a markdown (myfile.md) version that can be directly seen on GitHub. The markdown file on GitHub works much better for...

Rmarkdown font size and header

r,rmarkdown
I recently opened a standard Rmd file without editing anything. The default file looks like this: Untitled.rmd --- title: "myfile" author: "Me" date: "May 25, 2015" output: html_document fontsize: 12pt --- This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word...

Rmarkdown html matrix output width too narrow

html,css,r,rmarkdown
I'm aware of the existing options to make output wider : option(width=200) The issue is when using rmarkdown to go straight from an R file to html, the output is bounded by the size of the html box, not the predetermined R option for line width. What is the CSS...

Hide shiny output

r,shiny,rmarkdown
How do you hide rendered shiny output? Specifically, I have some figures/tables generated by shiny and I have a button, that when clicked should hide the figures/tables, and when clicked again should show them. This is what I have so far (below), and it works somewhat, but where it's supposed...

Pandoc Error in Slidify: Customizing First Slide Goes Wrong

pandoc,rmarkdown,slidify
I am using "slidify", "slidifyLibraries" and R Version 3.1.2 + RStudio Version 0.98. To knit the slidify slides I use the knitHTML-button. I have my own styles that I would like to use, but when I add a class tag, id tag or both to the first slide (code directly...

Render font size of maths in Rmarkdown slides when viewed in then Rstudio viewer

r,markdown,rstudio,rmarkdown,mathjax
Writing some slides for lecture. I want to include a shiny app. I do not have admin rights on the lecture room computer, which means I can run my Rmd file and present the slides via the Rstudio viewer, but they will not display in a web browser. All the...

Add beamer frame options in knitr/rmarkdown

r,latex,knitr,rmarkdown,beamer
I'm trying to add frame numbers to my Beamer presentation written in rmarkdown. However, I would like to suppress the numbers on the title page using the \begin{frame}[plain] option (from the second answer here: http://tex.stackexchange.com/questions/82794/removing-page-number-from-title-frame-without-changing-the-theme). However, when compiling from rmarkdown to tex, the \titlepage already creates a frame environment, so...

R: output a pivot-like table with subtotals

html,r,pivot-table,rmarkdown,xtable
I'm trying to make a cross tabulation in R, and having its output resemble as much as possible what I'd get in an Excel pivot table. The objective is to replace a report made manually with Excel and Word with one automated with R Markdown; data wrangling and charts have...

R markdown rerun the same section of report with different parameter

r,rmarkdown
I'm familiar with R markdown "parameters". However, say I want to generate the same report (same chart, same table) but for 5 different regions. Is there a way to do this elegantly in a loop or lapply or do I need to make several sections. So in pseudo code I...

Controlling digits / rounding as argument in base functions

r,rounding,rmarkdown,digits
In scientific paper writing, values are typically reported as rounded values with one, two or three digits, often depending on the type of value reported. This means that everytime when e.g. including an inline mean value in Rmarkdown I have to add round to the code. Thus I am wondering:...

Display two rCharts NVD3 figures next to each other in rmarkdown

r,nvd3.js,rmarkdown,rcharts
I want to display two charts with the rCharts package, one next to the other, more or less like the two pies are displayed in this link: http://nvd3.org/examples/pie.html I have a partial solution using <iframe>, but the solution has three problems: It is too case specific Including controls becomes a...

Markdown reverse ordered list?

markdown,rmarkdown
Is there a way to display a reverse-ordered list in plain Markdown? I read about the HTML "reverse" option (How to display a reverse-ordered list in HTML?, http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ol_reversed) but would favor a Markdown solution if that exists. To clarify, is there a way to write something like: 0. Coffee 0....

rmarkdown - Increasing html width to fit entire table

r,knitr,rmarkdown
I was looking for a way to change the setting in my Rmd file so that the html output contains all the columns and the table does not break. I tried to change the css properties as in this solution (Output table width in Rmarkdown) but this does not affect...

Keep trailing zeros for percents only

r,rmarkdown,pandoc,pander
Given the following example: library(pander) tableAbs <- Titanic[1, 1, , ] tablePct <- round(prop.table(tableAbs) * 100, 2) table <- cbind(tableAbs, tablePct) pander(table) ---------------------------------- &nbsp; No Yes No Yes ----------- ---- ----- ----- ----- **Child** 0 5 0 2.78 **Adult** 118 57 65.56 31.67 ---------------------------------- I would like to keep all...

Highlighting bash code with knitr / rmarkdown

r,syntax-highlighting,rstudio,knitr,rmarkdown
I'm trying to generate an HTML report using RStudio, R Markdown and knitr. In the report I would like to display some bash code. I do not want to run the code but I would like it to be highlighted. It has been mentioned in another question but the suggestion...

Howto include js dependencies of DT datatable in Rmarkdown using knitr and pandoc

r,datatable,rstudio,rmarkdown
Is there a way to compile RMarkdown documents with datatables produced by DT outside of RStudio? I'm trying to include a datatable widget in an RMarkdown document that I then want to convert to html using knitr and pandoc. This works fine with RStudio but if I try to do...

Reactive subset in ddply for rmarkdown shiny

r,shiny,subset,rmarkdown
I am trying to calculate and plot % yield of some data based on user definable inputs. I am using rmarkdown and shiny to do this. I keep getting stuck when passing a reactive subset through ddply to count the number of rows in the subset.."invalid (null) left side of...

call RMarkdown on command line using a.R that is passed a file

r,command-line,automation,argument-passing,rmarkdown
In summary, I am using my script 'Graphs.R' on 'input_file1.txt' in RStudio to create a Rmd which I then knit to html. I would like to automate this process to run more files on the command line. So far, I can get the Rscript to run on the command line...

How to include RMarkdown file in r package? [duplicate]

r,knitr,rmarkdown
This question already has an answer here: Include data examples in developing R packages 2 answers I'm in the process of creating a package in R and I also want to include an R Markdown file. This RMarkdown template contains functions from my package, and is rendered to an...

Automatically generated reports using rMarkdown

r,rmarkdown
I am trying to generate about 50 reports with the same template in rMarkdown. I do not want to change the name of the input file every time and I would like to choose different names for output files. Is there any way how to automate this process? Thank you....

Inputenc/Pandoc error when knit to Pdf on Rstudio Version 0.98.994

r,knitr,rmarkdown
I am getting an error to knit a Rmd document to pdf. Here is the part of the code causing the error. ```{r chunk5 ,echo=F} hypoconf<-function(z){if(z=="dose"){ cat(paste(as.character(1),"\b. If there is no difference in tooth growth for" ,z, "of",as.character(20),"and" as.character(10),"the probability of seeing the observed or more extreme outcome is", as.character(30),"percent."))...

How to bold a cell in a table (kable) in rmarkdown?

r,markdown,knitr,rmarkdown
Is there a way to format a single cell in a table in rmarkdown? I am using kable to generate a table, library(knitr) kable(data.frame(c('a','b','c'),c(1,2,3))) I wish to bold "c" in the last row and also add a horizontal line at the end of the table. Any pointers? Edit: Made a,b,c...