r-markdown

Knitr: print text from code block as R markdown

爱⌒轻易说出口 提交于 2020-05-11 04:44:04
问题 I have the following R Markdown document: --- title: "Test" output: html_document --- ```{r cars, echo=FALSE} myCondition <- TRUE if(myCondition) { print("## Car Summary") } summary(cars) ``` When I Knit it to HTML, the "Car Summary" header is rendered in "terminal-like" monospaced font as this: ## [1] "## Car Summary" But I want it rendered as a header. How do I achieve this? 回答1: This should work for you: ```{r cars, echo=FALSE, results='asis'} myCondition <- TRUE if(myCondition) { cat("##

Html output takes too long to load

只愿长相守 提交于 2020-05-09 07:55:32
问题 I have this html knit output from Rmarkdown but since it is pretty heavy (it is an online guide), the page takes too long to show up when opening the link. I tried to divide the rmd file into distinct rms sub files as below shown but I still can't get the result. Thank you title: "my_file" author: "me" date: "26/02/2020" output: html_document: toc: yes toc_depth: 3 toc_float: collapsed: yes smooth_scroll: yes word_document: default --- ```{r child = 'child0.Rmd'} ``` ```{r child = 'child1.Rmd

Html output takes too long to load

吃可爱长大的小学妹 提交于 2020-05-09 07:53:29
问题 I have this html knit output from Rmarkdown but since it is pretty heavy (it is an online guide), the page takes too long to show up when opening the link. I tried to divide the rmd file into distinct rms sub files as below shown but I still can't get the result. Thank you title: "my_file" author: "me" date: "26/02/2020" output: html_document: toc: yes toc_depth: 3 toc_float: collapsed: yes smooth_scroll: yes word_document: default --- ```{r child = 'child0.Rmd'} ``` ```{r child = 'child1.Rmd

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

时光怂恿深爱的人放手 提交于 2020-05-08 09:08:30
问题 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" when knitted from RStudio. (A bit like \include{} in LaTex.) The resulting RMarkdown PDF should thus display a not-evaluated verbatim copy of the R code from "code.R". The end goal is to make a RMarkdown file which

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

谁都会走 提交于 2020-05-08 09:07:06
问题 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" when knitted from RStudio. (A bit like \include{} in LaTex.) The resulting RMarkdown PDF should thus display a not-evaluated verbatim copy of the R code from "code.R". The end goal is to make a RMarkdown file which

In Bookdown, `\textcolor` is not recognized when I attempt to compile an epub book using Pandoc

北城余情 提交于 2020-05-01 03:37:58
问题 In bookdown, it appears that \textcolor in latex is not recognized when I try to compile using bookdown::render_book('bookdown::epub_book') even though I have added \usepackage{xcolor} into the preamble.tex file. Is there a reason for this? 回答1: Let's have a look at the way the document is processed. I will leave out processing by the knitr and R Markdown packages and focus on pandoc, which is the final step when converting from Markdown to any other format. Pandoc first parses the document

In Bookdown, `\textcolor` is not recognized when I attempt to compile an epub book using Pandoc

萝らか妹 提交于 2020-05-01 03:37:12
问题 In bookdown, it appears that \textcolor in latex is not recognized when I try to compile using bookdown::render_book('bookdown::epub_book') even though I have added \usepackage{xcolor} into the preamble.tex file. Is there a reason for this? 回答1: Let's have a look at the way the document is processed. I will leave out processing by the knitr and R Markdown packages and focus on pandoc, which is the final step when converting from Markdown to any other format. Pandoc first parses the document

How can I knit a Rmarkdown file into a html file which embeds plots?

↘锁芯ラ 提交于 2020-04-30 09:25:38
问题 In a Rmd file, there are several places which generate plots, for example ```{r outliers} influencePlot (model1) ``` I knit the file into a html file and several image files under directory ./figure/ , by running in a R session > library(knitr) > knit("my.Rmd") and then running in a bash session $ pandoc my.md -f markdown -t html -s -o my.html but the html file doesn't embed the plots from the image files, for example: <img src="figure/outliers-1.png" alt="plot of chunk outliers" /> I was

How can I knit a Rmarkdown file into a html file which embeds plots?

一曲冷凌霜 提交于 2020-04-30 09:21:07
问题 In a Rmd file, there are several places which generate plots, for example ```{r outliers} influencePlot (model1) ``` I knit the file into a html file and several image files under directory ./figure/ , by running in a R session > library(knitr) > knit("my.Rmd") and then running in a bash session $ pandoc my.md -f markdown -t html -s -o my.html but the html file doesn't embed the plots from the image files, for example: <img src="figure/outliers-1.png" alt="plot of chunk outliers" /> I was

Is there a way to keep full margins in ggplot2 pdf output?

こ雲淡風輕ζ 提交于 2020-04-16 05:47:10
问题 In this answer https://stackoverflow.com/a/61017301/2554330 I partially answered a problem in resizing subfigures in ggplot2 output using code similar to this: --- title: "Untitled" header-includes: - \usepackage{subcaption} output: pdf_document: keep_tex: TRUE --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r, echo = FALSE, fig.height=3, fig.width=1,fig.subcap=c("first", "second", "third"),fig.cap="Main"} library(ggplot2) df <- data.frame( x = rnorm(30), y = rnorm