knitr

knit_child in a Rmd file is printing unwanted output

喜夏-厌秋 提交于 2020-01-01 05:01:05
问题 I had succesfully used knit_child for generating pdf files, following the code of http://yihui.name/knitr/demo/child/, but when I try to use that example in a .Rmd file: ```{r, results='asis', echo=FALSE, message=FALSE} out = NULL for (p in c("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10")) { out = c(out, knit_child('quick_variable.Rmd')) cat(out) } ``` (I modify the original code, for work in Rmd ). I have two problems, the first one: | | | 0% | |... | 5% ordinary text without R code | |

knitr templates and child documents in a loop

风格不统一 提交于 2020-01-01 04:43:10
问题 Before Christmas I previously asked single style sheet across multiple knitr documents. I now know that the key search term I was missing is "child document". I have created a minimal markdown example but I am getting headers in the created document that are part of the knitting process. I am using RStudio to process it. I have seen many similar questions, but none of the answers work. I have tried various combinations of the chunk parameters and so far to no avail. Question: How do I get rid

How to make a figure caption in Rmarkdown?

假如想象 提交于 2019-12-31 13:44:15
问题 I am thinking about writing my thesis with rmarkdown and latex. I'm getting the hang of how it all works, however, when I try to add a figure (not an R plot) to the text and render it to pdf, the caption and in-text reference dissappear. This is the code snippet I use to add a figure: --- title: "Untitled" output: pdf_document --- see figure \ref{fig1}. ![picture \label{fig1}](figure1.png) This is what knitr creates: This is what pandoc creates: Question: How do I make figure captions and in

How to make a figure caption in Rmarkdown?

孤者浪人 提交于 2019-12-31 13:43:41
问题 I am thinking about writing my thesis with rmarkdown and latex. I'm getting the hang of how it all works, however, when I try to add a figure (not an R plot) to the text and render it to pdf, the caption and in-text reference dissappear. This is the code snippet I use to add a figure: --- title: "Untitled" output: pdf_document --- see figure \ref{fig1}. ![picture \label{fig1}](figure1.png) This is what knitr creates: This is what pandoc creates: Question: How do I make figure captions and in

Reduce cell width and font size of table using pandoc.table()

余生颓废 提交于 2019-12-31 12:25:12
问题 I'm using knitr and pander to make a table in a markdown file. I'm converting the markdown file to a PDF using Pandoc from within R. This code: library(knitr) ```{r myTable, echo=FALSE, message=FALSE, results='asis', comment=""} library(pander) pandoc.table(head(iris)) ``` then running this function within R: knitsPDF <- function(name) { knit(paste0(name, ".Rmd"), encoding = "utf-8") callformat <-"pandoc -V geometry:margin=1in %s.md -o %s.pdf" system(sprintf(callformat, name, name)) }

How to place xtable object to the left side of page

天大地大妈咪最大 提交于 2019-12-31 04:30:31
问题 Question: How to place xtable object to the left side of page or how to disable centering globally. I'm struggling to figure out how to place xtable object on the left side. I have got a *.Rmd file and all this goes to the relevant r chunk. require(xtable) df <- data.frame(x=seq(1,10,1),y=rnorm(10)) Xtab <- xtable(df, digits=0, caption="\\textbf{MINIMAL/IDEAL}", floating=FALSE, latex.environments = c("left")) print(Xtab, size = "small", include.colnames=FALSE) I have included the following

Producing ggplots from a loop (and generating the files) without printing any visible output in RMarkdown

百般思念 提交于 2019-12-31 03:43:05
问题 I am building a table with a mixture of numbers, text, and plots. I constructed my plots with ggplot, and added them to the table afterwards (please see code below). Because I will (eventually) have many plots, I need to use a loop to efficiently create them all. However, because ggplot seems to require printing to generate image links for each plot, I am unable to use invisible() , and subsequently get the pesky '[1] [[2]] [[3]]' output at the top of the image below. How can I compile the

Headers in Knitr

戏子无情 提交于 2019-12-31 01:56:28
问题 Is there a way to use knitr from within the R console ( not RStudio) to process a header. There are many examples using YAML headers such as: --- title: "Habits" author: John Doe date: March 22, 2005 output: html_document --- However, is there a way to have this header included using knit2html from within the R console? Thanks! 回答1: No, the YAML metadata is specific to R Markdown v2, i.e. the rmarkdown package. The knitr::knit2html() function is for R Markdown v1 only. 来源: https:/

Extract only text from Rmd documents

泄露秘密 提交于 2019-12-31 00:58:15
问题 Not even sure if this is possible, but is there a way to extract only the raw text portion of the .Rmd file and discard any code? Or basically converting an .Rmd file into .txt file within R? I've tried the function readLines , but this makes a huuuuuge character with all kinds of (to me) useless meta-data. 回答1: You can knit document without evaluating and including code. Here's an example of dummy document foo.Rmd : # Header 1 foo ## Header 2 bar ## Header 22 foobar ```{r} 1 ``` text text

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

折月煮酒 提交于 2019-12-31 00:18:15
问题 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 ## Sub headline 1.1 ## Sub headline 1.2 ### Sub sub headline 1.2.1 # Headline 2 The TOC of the resulting HTML document will look like this (with the unwanted bullet points - here indicated