knitr

How to insert markdown in the middle of an knitr R code chunk?

有些话、适合烂在心里 提交于 2019-12-12 22:24:48
问题 For example, I would like to insert a break between each of the two plots in the following code chunk without breaking it up: ```{r} plot(1:100, 1:100) plot(1:100, 1:100) ``` such that the result is like: ```{r} plot(1:100, 1:100) ```` <br> ```{r} plot(1:100, 1:100) ``` If results='asis' is a chunk option, it looks like you can directly print the <br> command, e.g.: ```{r} plot(1:100, 1:100) print('<br>') plot(1:100, 1:100) ``` What do I do for other types of chunks? 回答1: You can use the

R Notebook/Markdown does not save chunk plots using “fig.path = ” chunk option

♀尐吖头ヾ 提交于 2019-12-12 22:19:38
问题 I'm running an analysis in an R Notebook and I would like all plots created in R chunks to be saved as individual PDF files in addition to appearing in the .nb.html notebook output. The problem The problem I'm having is that, when the notebook is run, it does not save plots to the dir specified in the chunk option fig.path = "figures/" either when specified in the individual chunk header: #```{r fig.path = "figures/"} plot(x, y) #``` or when specified with the global chunk options: #```{r

Knitr pandoc Execution halted in R

可紊 提交于 2019-12-12 18:30:31
问题 Knitr / Rmarkdown Execution halted When I run Knitr and Rmarkdown, even with the knitr example scripts, I get the below error message . Error in system(paste(shQuote(pandoc_path), "--version"), intern = TRUE) : '"C:/Program Files/RStudio/bin/pandoc/pandoc"' not found Calls: <Anonymous> ... get_pandoc_version -> with_pandoc_safe_environment -> force -> system Execution halted I have installed and loaded knitr and rmarkdown from the libraries and alternatively using dev tools to get the most

Include label attribute into xtable header

别来无恙 提交于 2019-12-12 18:19:37
问题 Reproducible example: I have a data frame which has labelled variables using the sjmisc package, which works nicely together with dplyr since v0.4.2. library(dplyr) library(sjmisc) library(ggplot2) data("diamonds") df= tbl_df(diamonds) %>% select(cut, carat, price) %>% set_label(c("", "Kt", "EUR")) %>% slice(1:10) As str(df) shows it properly contains for two columns the labels: Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 10 obs. of 3 variables: $ cut : Ord.factor w/ 5 levels "Fair"<"Good"<..:

Can `knitr` suppress execution or output in an sql chunk?

只谈情不闲聊 提交于 2019-12-12 16:02:23
问题 The document below runs the sql and shows the results. I don't want any output to show up, either by not running the chunk, or by hiding the output. Is there a way to do this? --- output: html_document --- ## Hide SQL Output First, set up a temporary database: ```{r} library(RSQLite) conn <- dbConnect(SQLite(), tempfile()) df <- data.frame(value = runif(1)) dbWriteTable(conn, "TestTable", df) ``` Now show a query, but try not to run it, and try to hide the output. Neither works: it runs, and

How do I use the ggmap library's get_map function inside of knitr?

删除回忆录丶 提交于 2019-12-12 15:15:17
问题 All of my R code runs as expected in a standalone script. Once inside an R Markdown file the get_map() call breaks down. map <- get_map(location = 'minneapolis', zoom = 9) I get an error: label: unnamed-chunk-2 Warning in sink() : no sink to remove label: unnamed-chunk-2 Error in process_file(text) : Quitting from lines 53-64: Error in close.connection(con) : invalid connection Calls: knit -> process_file Execution halted knitr terminated with status 1 Any ideas why knitr and get_map aren't

modify font color for R code in latex document using listings

北战南征 提交于 2019-12-12 15:13:41
问题 I am trying to highlight R code in a Latex document, but I can't seem to change the font colors inside the code box. For instance, I think commentstyle=\color{red} should give me red font for the comments, but comments appear in either blue or black (can't quite tell). Also, I think backgroundcolor=\color{white} should give me a white background... I'm using knitr and RStudio to write and compile the pdf. Example below. \documentclass{article} \usepackage{inconsolata} \usepackage{listings}

How to knit/Sweave to a different file name?

倖福魔咒の 提交于 2019-12-12 13:12:58
问题 By default, the knit/Sweave command will generate a tex file with the same name as the .Rnw file. I want to give it and the subsequent pdf file a different name is it possible? 回答1: In the header of an .Rmd file, you can specify a file name: --- title: "My title" output: pdf_document: pandoc_args: [ "--output=Custom_name.pdf" ] --- For .Rnw files you can directly call the function knitr::knit2pdf : knit2pdf(input.Rnw, output="Custom_name.pdf") 回答2: @mrub, knit2pdf(input.Rnw, output="Custom

pkgdown vignette code chunk spacing

核能气质少年 提交于 2019-12-12 13:08:21
问题 I'm having issues with code chunk output when running pkgdown::build_site() with all default options. Chunks are rendered in html content with superfluous white space in between every line of code. For example: ```{r, message = FALSE} library(leaflet) leaflet(toronto) %>% addProviderTiles(providers$CartoDB.Positron) %>% addPolygons() ``` Comes out as: library(leaflet) leaflet(toronto) %>% addProviderTiles(providers$CartoDB.Positron) %>% addPolygons() Or, in screenshot form: I haven't faced

unable to change the colors of the xtable cells in rmarkdown output to pdf

99封情书 提交于 2019-12-12 12:58:56
问题 I have this r markdown code: --- header-includes: - \usepackage{xcolor, colortbl} output: pdf_document: latex_engine: xelatex --- ```{r, results="asis"} library(xtable) library(formattable) # Your data tab = data.frame(category = c("A","B","C"), groupA = c(.2,.3,.5), groupB= c(.6,.7,.9)) # Function to cut your data, and assign colour to each range f <- function(x) cut(x, c(0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, Inf), labels=c("green", "red", "blue", "orange", "yellow", "purple", "brown",