r-markdown

Automating the generation of preformated text in Rmarkdown using R

梦想的初衷 提交于 2019-12-01 20:24:34
I'm creating a document in which I repeat the same formatting multiple times. So I want to automate the process using the for loop in R. Here's a simple example. Assume, I have an R code that computes some information for all cut values in ggplot2::diamonds dataset, which I want then to print in my document in five separate sections (one section per cut): library(knitr); library(data.table) dt <- data.table(ggplot2::diamonds) for (cutX in unique(dt$cut)) { dtCutX <- dt[cut==cutX, lapply(.SD,mean), .SDcols=5:7] #### START of the Rmd part that needs to be printed # Section: The Properties of Cut

render leaflet plots as raster in R?

走远了吗. 提交于 2019-12-01 20:07:11
问题 I realize that this largely defeats the purpose of using an interactive leaflet map, but I'm writing a traditional paper book and I want to show how the leaflet package for R works. I'm writing the book in LaTeX and rendering with knitr . Is there a way to have a leaflet map render as a raster image such that it could be included in this book? Here is a minimal example: library(leaflet) map <- leaflet() %>% addTiles() %>% addMarkers(lng = -77.03673, lat = 38.89761) Now if I try a chunk like:

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

狂风中的少年 提交于 2019-12-01 19:55:25
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 via the * char): Untitled Author 01/25/2015 * 1 Headline 1 * 1.1 Sub headline 1.1 * 1.2 Sub headline 1.2

creating accompanying slides for bookdown project

别说谁变了你拦得住时间么 提交于 2019-12-01 19:24:45
In Rstudio, I create a new project and select book project using bookdown . The built in example runs perfectly as expected and i can compile 4 books - gitbook, html, epub, and pdf. Great. The next obvious step is to want to have slides at the same time, very much in line with what the beamer package does, allowing for both beamer mode and article mode . Therefore, I tried to add another output in the _ output.yml code: bookdown::pdf_document2 . In line with the documentation, I know I should be able to define the base_format to use rmarkdown::beamer , The package author told me I was almost

Extract only text from Rmd documents

白昼怎懂夜的黑 提交于 2019-12-01 18:36:51
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. 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 text ```{r} print(2) ``` We can knit this document using knitr::knit("foo.Rmd") , but in this case code chunks

render leaflet plots as raster in R?

跟風遠走 提交于 2019-12-01 18:21:14
I realize that this largely defeats the purpose of using an interactive leaflet map, but I'm writing a traditional paper book and I want to show how the leaflet package for R works. I'm writing the book in LaTeX and rendering with knitr . Is there a way to have a leaflet map render as a raster image such that it could be included in this book? Here is a minimal example: library(leaflet) map <- leaflet() %>% addTiles() %>% addMarkers(lng = -77.03673, lat = 38.89761) Now if I try a chunk like: <<>>= map @ I get this error: Error in validateCssUnit(sizeInfo$width): "\maxwidth" is not a valid CSS

Error in loadNamespace(name) : there is no package called 'evaluate'

亡梦爱人 提交于 2019-12-01 18:04:43
问题 While adding code chuncks to my .rmd file a la: ```{r} %code chunck ``` it can't be compiled anymore, and i get a loadnamespace(name) error: Error in loadNamespace(name) : there is no package called 'evaluate' calls:<Anonymous> ... tryCatch-> Trycatchlist->trycatchoone Has anyone ever experienced it? And how do I resolve it? 回答1: Try install.packages("evaluate") and then reattempt compilation. It was probably uninstalled unintentionally at some point. 回答2: if it is not installed after tying

Error in loadNamespace(name) : there is no package called 'evaluate'

我们两清 提交于 2019-12-01 18:01:30
While adding code chuncks to my .rmd file a la: ```{r} %code chunck ``` it can't be compiled anymore, and i get a loadnamespace(name) error: Error in loadNamespace(name) : there is no package called 'evaluate' calls:<Anonymous> ... tryCatch-> Trycatchlist->trycatchoone Has anyone ever experienced it? And how do I resolve it? Try install.packages("evaluate") and then reattempt compilation. It was probably uninstalled unintentionally at some point. if it is not installed after tying install.packages('evaluate') then,press ctrl + shift + f10 on RStudio console so this command will restart R

Rmarkdown removes citation hyperlink

穿精又带淫゛_ 提交于 2019-12-01 17:50:32
when using Rmarkdown to build a pdf with citations included, it removes the hyperlinks of the citations by default. Looking at the latex file produced, I can see \usepackage{hyperref} in the pre-amble, but the citations look as follows: rmd input: @sharpe latex output: sharpe (1999) Thus it produces a non-dynamic citation in pdf. The latex output that I would expect is: \citet{sharpe}, which produces hyperlinked citation in pdf. Any ideas why it writes out my bibtex inputs like this and how I can make it hyperlinked? Thierry By default pandoc will do the rendering of the citations. I see two

Rmarkdown not outputting results of system command to html file

孤街醉人 提交于 2019-12-01 17:35:56
I'm new to using Markdown, and have looked for a similar problem to this on SO without success. I'm using Rmarkdown (with Rstudio and knitr) to write a vignette that describes reading in a datafile which is imported as part of the package. I can correctly access the datafile using > system.file("extdata", "Marlin-tag38606.txt", package = "xtractomatic") I want to show the first few lines of this file in the vignette, so my code reads ```{r, results=as.is} datafile <- system.file("extdata", "Marlin-tag38606.txt", package = "xtractomatic") system(paste("head -n5 ",datafile)) ``` The problem is