knitr

knitr Rnw latex: how to obtain a figure and caption in landscape mode that's full page width

微笑、不失礼 提交于 2019-12-11 02:49:52
问题 I am trying to produce a full-page figure along with a caption in landscape mode. The Rnw file below works fine if I omit "fig.cap='Caption Trial'", but not if the caption is used. Any help would be greatly appreciated. \documentclass{article} \usepackage{fullpage} \usepackage{pdflscape} \begin{document} \begin{landscape} <<test, out.width='1\\linewidth', fig.width=7, fig.height=4, fig.cap='Caption Trial'>>= par(mar=c(4, 4, .1, .1)); plot(1:10) @ \end{landscape} \end{document} 回答1: Try this:

Custom output hooks in knitr

落花浮王杯 提交于 2019-12-11 02:40:02
问题 I am trying to create a chunk hook that can produce a \floatfoot{} as part of the output from a chunk. Hopefully the following example makes clear what I am trying to achieve: 1. .Rnw file Here is the knitr file. \documentclass[a4paper]{article} \title{Learn Moar knitr!} \author{Foo Bar} \date{\today} \usepackage{blindtext} \usepackage{floatrow} \begin{document} \blindtext <<label=plotWithNotes, fig.lp='fig:', fig.cap='This is a figure'>>= plot(rnorm(100), rbinom(n = 100, size = 1, prob = 0.5

Lyx cannot find knitr module

这一生的挚爱 提交于 2019-12-11 02:36:16
问题 I am migrating/branching from sweave to knitr and can run @yihui's minimal example in Rstudio but am having trouble making it run with Lyx (2.06). I get the message The module knitr has been requested by this document but has not been found in the list of available modules. My PATH is /usr/bin/Rscript (per which Rscript , as per @yihui's suggestion here) so that appears visible, but lyx doesn't seem to see it. I also did upgrade to R version 3.0.1 (Good Sport) today as a part of a larger

Format inline output conditional on textual context

别来无恙 提交于 2019-12-11 02:04:13
问题 Using a modification (adapted from Jason French's blog post here) to the default inline knitr hook, I am printing numeric output rounded to 3 decimal places. If the value is less than 0.001, it returns "< 0.001". Here's an MWE showing the hook modification, and how I might use it in practice in R Markdown: ```{r setup, echo=FALSE} library(knitr) inline_hook <- function(x) { if (is.numeric(x)) { res <- ifelse(x == round(x), sprintf("%d", x), sprintf("%.3f", x) ) res <- ifelse(x < 0.001, '< 0

Printing ggplots out of list does not work in knitr with rmarkdown

房东的猫 提交于 2019-12-11 00:29:01
问题 I would like to put ggplots into a list and then later print each one in the list. That should be done with rmarkdown and knitr in RStudio. MWE (of course, in real, the list gets filled somewhere else than printed): --- title: "nice title" author: "Me" date: 12\. Januar 2016 output: pdf_document: fig_caption: yes fig_width: 7 keep_tex: yes number_sections: yes toc: yes html_document: default --- Here is my plot: ```{r, echo=F} library(ggplot2) printGGlist <- function(gglist){ for(gg in gglist

Caption not appearing for LaTeX table when knitting using Hmisc LaTeX Function

我的未来我决定 提交于 2019-12-10 23:59:28
问题 I am trying to create a LaTeX table using the table and Hmisc packages however, I am having trouble getting the caption to appear. Here is a reproducible example: ```{r, results = "asis"} # data: dow <- sample(1:7, 100, replace=TRUE) purp <- sample(1:4, 100, replace=TRUE) dow <- factor(dow, 1:7, c("Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun")) purp <- factor(purp, 1:4, c("Business", "Commute", "Vacation", "Other")) dataframe <- data.frame( dow, purp) # The packages library(tables)

Markdown Report Not Executing in Rstudio

三世轮回 提交于 2019-12-10 23:57:44
问题 I am generating the error: > options(encoding='UTF-8'); require(knitr); knit('March-2013-Report.Rmd'); Loading required package: knitr processing file: March-2013-Report.Rmd |...................... | 33% ordinary text without R code |........................................... | 67% label: unnamed-chunk-1 Quitting from lines 4-5 (March-2013-Report.Rmd) Error in evaluate(code, envir = env, new_device = FALSE, stop_on_error = if (options$include) opts_knit$get("stop_on_error") else 2L) : unused

R markdown compile error:

无人久伴 提交于 2019-12-10 23:09:16
问题 When I try to compile an Rmarkdown document to pdf, I get this error: Error: Functions that produce HTML output found in document targeting latex output. Please change the output type of this document to HTML. Alternatively, you can allow HTML output in non-HTML formats by adding this option to the YAML front-matter of your rmarkdown file: always_allow_html: yes Note however that the HTML output will not be visible in non-HTML formats. Does anyone know what this means? 回答1: Have you tried the

Embedding plotly graphs in a Rmarkdown document using source(“filename.R”)

家住魔仙堡 提交于 2019-12-10 22:58:48
问题 I am creating a RMarkdown HTML document where chunks are sourcing R files: ```{r } source("test.R") ``` Where test.R is: library(ggplot2) library(plotly) data <- as.data.frame(datasets::mtcars) create_plot <- function(data, var_x, var_y, var_color, var_size) { data %>% ggplot(aes_string( x = var_x, y = var_y, color = var_color, size = var_size)) + geom_point() } p <- create_plot(data, "disp", "qsec", "vs", "hp") p <- ggplotly(p) print(p) This works inline the Rmarkdown document (RStudio) but

knitr sql chunk not saving data into variable

感情迁移 提交于 2019-12-10 21:53:40
问题 My RMarkdown notebook with a SQL chunk runs fine when I run all the chunks one by one interactively, but when I try to knit, the SQL chunk does not have save the data into the specified variable. When the dataset that was supposed to be generated using the SQL chunk is referenced in later R chunks, the dataset variable is simply empty. Here's an example {r setup, include=FALSE, warning=FALSE, message=FALSE} # load necessary libraries library(bigrquery) library(knitr) library(tidyverse) db <-