FAQ Database Discussion Community

## How to hide figures in knitr, but create them as png?

r,knitr,figure
I am currently doing some statistical analysis in R and use knitr to generate results and an overview document. There are some additional plots, which I want to be done and saved as a .png (with specified file name and location), but not included in the generated .html file (too...

## Enforce PDF package vignette with knitr

r,pdf,knitr,vignette
I have a vignette for my package which compiles to a nice PDF when compiled with Rscript -e 'rmarkdown::render("tmod.rmd")'. However, when I compile and install the package, start R and type vignette("mypackagename"), a browser window opens with ugly looking HTML, without a title, without a table of contents and without...

## Value not being returned using Knit

r,knitr
I am trying to have a table and some values returned from a function, using this: r TabelaTipos("T") r MinDPA It was supposed to return a table and the min standard deviation, but its only returning an error. If I remove r MinDPA, it returns the table like a charm,...

## Loops, knitr and xtable in rmarkdown to create unique tables in multiple reports

r,knitr,xtable
I'm revising my question in full. I realized it was long, and my point was getting lost. Here's what I need to do: Create automatic reports for schools that contain tables that compare their data to the district that school is in as well as the whole state. The State...

## 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. ---...

## 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...

## 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 ##...

## 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...

## 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."))...

## 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 do I add a note or text in addition to the caption to a knitr figure for latex output?

r,latex,knitr
I am using knitr to write my thesis and compiling it as a latex document. I have successfully included figures with the appropriately labeled caption; however, in addition to the caption I would like to include additional lines of text directly below the caption and associated with the figure. For...

## r knitr - embedded HTML tags being escaped - how to turn off

html,r,knitr
I am having a little trouble with knitr and embedded html tables. Basically what is happening is when I embed xtable output in html, the html tags are being escaped rending the output unreadable. the output of print.xtable does seems to correctly produce the expected output (an html table) but...

## 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...

## 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...

## 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...

## dev='png' is not working for pdf output in knitr

r,knitr
In the default setting, knitr will use "'pdf' for LaTeX output and 'png' for HTML/markdown". However, I can specify the dev = "png" in the chunk options for the LaTeX output. This feature is very useful to reduce the file size for big vector figure (e.g. maps). In the previous...

## How to show greek letters as the rownames of a matrix

r,knitr
I am wondering how to set the rownames of a matrix including greek letters expressions in R. I use "expression", but it seems not working. Here is my code below. b.summary = matrix(0, 8, 6) colnames(b.summary)= c("Min.", "1st Qu.", "Median", "Mean","3rd Qu", "Max." ) rownames(b.summary)= c(expression(paste(tau, "=1", sep="")),expression(paste(sigma^2, "=1", sep="")),...

## 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 can I install packages in knitr?

r,markdown,knitr
Till now, I was using this chunk of code to load R packages and write .R files. But I am trying to use knitr rm (list=ls(all=TRUE)) kpacks <- c('ggplot2','install_github','devtools','mapdata') new.packs <- kpacks[!(kpacks %in% installed.packages()[,"Package"])] if(length(new.packs)) install.packages(new.packs) lapply(kpacks, require, character.only=T) remove(kpacks, new.packs) options(max.print=5.5E5) But now, when I put this chunk of...

## Adding XeTeX to ess-swv-PDF

r,emacs,knitr,sweave,ess
I am working with an .Rnw file with Hebrew in it, and I would like to compile the resulting .tex file using XeTeX. I work in Emacs, so I am using the Emacs Speaks Statistics (ESS) package, which allows a few options for compiling the .tex file. However, using XeTeX...

## 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...

## Insert HTML tables in knitr documents in R

r,knitr
I have a number of different HTML files that contain formatted tables which I would like to combine in a knitr report in R. Unfortunately, I have some issues in loading the HTML files into R and including the tables in my knitr report. The HTML files were created using...

r,markdown,knitr
I am knitting a markdown file called MyFile.rmd. How can I access the string MyFile during the knitting and use it for: use in the title section of the YAML header? use in subsequent R chunk? --- title: "r rmarkdown::metadata$title" author: "My Name" date: "10. Mai 2015" output: beamer_presentation ---... ## R knitr Add linebreak in table header kable() html,r,knitr I am using knitr to generate some reports. I use kable to generate an HTML table in the document. In the headers I want to use linebreaks (or other html tags) to enhance the table <!--begin.rcode results='asis' s <- rbind(c(1,2,3,4),c(1,2,3,4),c(1,2,3,4)) kable(s, col.names=c("Try Newline\nn","Try HTML break<br>%","Past 6 months\nn","\n%")) end.rcode--> As you... ## 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... ## R knitr print in a loop r,loops,knitr I've been using the xtable package to create HTML tables out of R matrices. When I used the function kable in a loop, it didn't output anything. So I stared using the print function, which worked. The problem is that when I use the print function I get lots of... ## ifelse works with mutate in R, why not in knitr? r,knitr,dplyr I have this line of code working in "normal" R: damage <- damage %>% mutate( EVTYPE = ifelse(grepl("winter", EVTYPE, ignore.case=T), "Winter Weather", EVTYPE)) However, the exact same line of code in knitr results in strange behavior. Instead of the value of EVTYPE being left alone if the grep fails, it... ## How can I use values and charts in a knitr / LaTeX document before R has calculated them? r,latex,knitr A knitr document contains sections of R and LaTeX. My boss wants to read the summary (in LaTeX), but doesn't want to read the R. However the R should be available in an appendix, so the code can be checked if needs be (see below). How to I make values... ## How to set the width/height of a plot in knitr? r,plot,knitr I have some R code, where I open a png() device to write a plot to, but I want this plot to also show in the PDF that I generate from the code using Knit-R. So far, I have done this: png(file="filename.png", width=5, height=5, units="in", res=300) dev.control(displaylist="enable") # Do the... ## Problems cross referencing in LaTex with knitr and xtable r,latex,knitr,xtable,cross-reference I am currently working with R Studio to produce PDF documents with R/knitr in LaTex. Within these documents I want to present part of my results in tables that I want to refer to in the text. I produce these tables using the xtable package within R and it is... ## 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]'... ## using -knitr- to weave Rnw files in RStudio r,rstudio,knitr This seems to be a recurrent problem for who is willing to write dynamic documents with knitr in RStudio (see also here for instance). Unfortunately I haven't find a solution on Stack Overflow or by googling more in general. Here is a toy example I am trying to compile in... ## How do I programmatically automate .rmd file to PDF using knitr? [closed] r,pdf-generation,reporting,knitr,rdoc I can produce my reports rather quickly thanks to knitr and RDoc; however I want to streamline my process a little more by automatically generating the documents in my R script. Do ya'lls have any solutions or resources I could use to further investigate to create a solution? ... ## R, knitr, xtable, using both add.to.row and hline.after r,knitr,xtable I’m trying to produce a table with xtable in R using knitr. I have inserted a header and extra \hlines. I’m using the add.to.row command to insert my header at the top, as well as midway through the table. I can’t seem to get the hline.after command correct. I would... ## 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... ## Using R Studio Console commands not parsed in Knitr markdown file r,rstudio,knitr Forgive the very basic question but I'm having some trouble getting the knitr feature to work just like typing in the console. To recreate Download this csv file https://s3.amazonaws.com/udacity-hosted-downloads/ud651/reddit.csv Import it into R Studio calling it reddit so it appears in the Global Environment area of the IDE, Do this... ## R Knitr PDF: Is there a posssibility to automatically save PDF reports (generated from .Rmd) through a loop? r,pdf,dynamic,report,knitr I would like to create a loop, which allows me to automatically save PDF reports, which were generated from a .Rmd file. For instance, if a variable "ID" has 10 rows, I would like R to automatically save me 10 reports, into a specific directory. These reports shall vary based... ## Controlling output while printing data.table with xtable r,data.table,knitr,xtable Here is a data.table with lots of records / rows: dt <- data.table(a=sample(letters,1000,replace = T), b=rnorm(1000)) We can view it using simply: dt ... and a very convenient view is generated with first and last 5 rows. However, when using xtable to print this using knitr for a pdf report,... ## LaTeX Equations Not Rendered on Webpage r,latex,markdown,knitr When I go to a webpage, such as this page of examples, none of the LaTeX code is being rendered in any of the browsers I try. However, on the same computer, if I create a simple R Markdown file in RStudio and I click Knit HTML, the preview in... ## 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.... ## 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... ## knitr rchart datatable dtable does not to render r,jquery-datatables,knitr,rcharts First, excuse my english, second i've read: rChart in R Markdown doesn't render 2 Knitr/R Markdown/Rstudio issues: Highcharts and Morris.js and doing that, I still have problems I install rCharts doing Install rCharts install.packages("devtools") library("devtools") install_github("ramnathv/rCharts") library("knitr") If I have a .Rmd like test.Rmd {r ,results='asis', comment= NA, echo=FALSE} library(rCharts)... ## Knitr not wrapping lines in R code chunks r,knitr I have problem with my R code blocks in my knitr reports, they don't wrap lines in almost all of my blocks with a R code. It's a typical Rmd file with blocks like this: {r} batch_merged <- sqldf(c("update batch_merged set winning = 'mix' where (Homophily_Count BETWEEN 1 AND Agents_Count... ## Run external R script n times and save outputs in a data frame r,knitr I have a R script of several hundreds of lines including several randomization functions. Each time I run it I obtain a different result. I am thinking of performing a sensitivity analysis of my model and I wold be interested in running my script hundreds of times and compare the... ## 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... ## Is there a way to include knitr documents in a LaTeX document? r,latex,knitr I think the question as stated maybe ambiguous, so let me describe my use case. I am working on a document that is primarily ordinary English text edited in a LaTeX editor (Texpad in my case), but in which I'd like to include material I've developed in knitr-based .Rnw file.... ## knitr displaying digits of an integer without scientific notation r,knitr when displaying a number with inline-code with more than four digits like r 21645 the result in a knitted html-file is this: 2.164510^{4} (in reality inside the inline-hook there is a calculation going on which results in 21645). Even though I just want it to print the number, like so:... ## R script to HTML with knitr. Complete basics r,knitr I was wondering how you could turn an R script into an HTML report (From the sounds of it using knitr is the way to go). I would like to do this without using RStudio if possible. Say I have to following R script #Load librarys + initilisation calculations #User... ## 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... ## Error in applying a for loop to an xtable in knitr r,latex,knitr,xtable I'm preparing a pdf using knitr that contains a table produced using xtable. I'm adding a bold typeface to certain cells in the table so I've written the following function: bold <- function(x, matrix){ x[] <- lapply(x, as.character) for (i in 1:ncol(x)) { yes <- matrix[,i] x[yes,i] <- paste('\\textbf{', x[yes,i],... ## How can knitr keep warning messages inside the box? r,knitr 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... ## Using Vim + latex-suite + knitr r,vim,latex,knitr (summary at the bottom) I have set up Vim and R using the Vim-R-plugin and it works flawless. I also use the Latex-suite in Vim and can create, compile and view .tex files without any problem. For knitr, I used to use Rstudio but I would really like to stay... ## 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... ## Setting work directory in knitr using opts_chunk$set(root.dir = …) doesn't work

r,rstudio,knitr
My R project is structured like a package with directories /R, /vignettes, /data etc. In one of my Rmd docs in /vignettes I source a script which in located in /R. Inside this script I use read.csv() to load a file located in inst/extdata/. The problem now is that by...

## 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...

## 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...

## 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 ->...

## How to hide function output in resulted PFD file in R knitr

r,knitr,rnw
I am building a report in R with the use of knitr. The file is of .Rnw extension and I compile it into PDF file. I faced a problem when using a woe::iv.mult function. Using this function causes some information being printed on the console and the same information is...

## 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 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...

## kable() in knit pdf appears oversized

r,table,pdf,latex,knitr
I am using the kable() function to output a table in a Rmd knit pdf document. I am however experiencing an issue with it. When I knit pdf, the table that it's outputting is oversized by width and ends-up being cropped. Please see below a mock code to run in...

## R knitr markown: Setting HTLM page width

css,r,knitr
I am using knitr to create a HTML webpage. The default setting seems to be 800px but I need a larger page size of 1100px body { max-width: 800px; margin: auto; padding: 1em; line-height: 20px ; } I have tried: library("markdown") library("knitr") knit2html("test.Rmd",options = c(width=1100)) But this still gives me...

## rmarkdown: page break within a chunk?

r,markdown,knitr
Is it possible to make each of the numbers show up on a separate page? --- title: "Page Break In Chunk" output: pdf_document --- {r} for(i in c(1:10)) { print(i) }  ...

## Modify external R script in a knitr chunk

r,knitr,rnw
I'm wondering if it's possible to hook into the code in an external R script that is read by knitr. Specifically, say that you have the following R file test.R ## ---- CarPlot library(ggplot2) CarPlot <- ggplot() + stat_summary(data = mtcars, aes(x = factor(gear), y = mpg ), fun.y =...

## 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 <-...

## Escaping quotes to submit sql in R Markdown using ODBC

mysql,r,knitr,rodbc
I can't figure out how to escape these quotes properly. How can I add SQL that requires quotes to denote strings near 'australia' and 'brazil'? The following as run in R Studio as R markdown. Error message is below. --- title: "Mobile Product Reporting" author: "super john" date: "Thursday, May...

## 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...