knitr

Generating view of cache object in Markdown document in R

被刻印的时光 ゝ 提交于 2019-12-20 06:24:32
问题 I cannot show object in markdown document that are objects generated in different R script(within the same session). I would like to point out that I am newbie to markdown. So the code is as follows(''' are added before and after): {r eval=TRUE, echo=FALSE} head(output_by_size,10) # 1st line summary(cars) # 2nd line dim(iris) # 3rd line when I comment line 2nd and 3rd the following error is generated: Error in head(output_by_size, 10) : object 'output_by_size' not found Calls: ...

To have R chunk in line with text using knitr

冷暖自知 提交于 2019-12-20 05:57:16
问题 How to have R code (R chunk) inline with my text? Example: Please install the package by using install.packages("ISwR") whereby, install.packages("ISwR") is automatically highlighted as R chunk using knitr? In other words, I would like to have R code at the same line with my text. 回答1: Following a suggestion from Yihui, \documentclass{article} <<setup, include=FALSE>>= knit_hooks$set(inline = function(x) { if (is.numeric(x)) return(knitr:::format_sci(x, 'latex')) knitr:::hi_latex(x) }) @

To have R chunk in line with text using knitr

天大地大妈咪最大 提交于 2019-12-20 05:57:10
问题 How to have R code (R chunk) inline with my text? Example: Please install the package by using install.packages("ISwR") whereby, install.packages("ISwR") is automatically highlighted as R chunk using knitr? In other words, I would like to have R code at the same line with my text. 回答1: Following a suggestion from Yihui, \documentclass{article} <<setup, include=FALSE>>= knit_hooks$set(inline = function(x) { if (is.numeric(x)) return(knitr:::format_sci(x, 'latex')) knitr:::hi_latex(x) }) @

knitr: code in chunks gets wrapped unexpectedly

冷暖自知 提交于 2019-12-20 05:10:10
问题 In a beamer presentation using knit2pdf() and LaTeX, I sometimes find that code in chunks gets wrapped, even though I have set tidy=FALSE globally. For example, this chunk: \item Fit this using \func{glm}: <<berk-logit2, size='footnotesize'>>= berkeley <- as.data.frame(UCBAdmissions) berk.logit2 <- glm(Admit == "Admitted" ~ Dept + Gender, data = berkeley, weights = Freq, family = "binomial") @ Appears like this: Note that all three lines are wrapped, as if in paragraph mode. The indented line

Pandoc's environment cslreferences undefined when knitting RMarkdown to PDF in RStudio

一笑奈何 提交于 2019-12-20 03:23:46
问题 Knitting (in RStudio version 1.2.1335) an RMarkdown file to PDF fails when trying to create citations (for pandoc version 2.8.0.1, and R version 3.6.1). (This does not happen when knitting to HTML, for example.) Here is a small rep. ex. in RMarkdown: --- title: "Rep. Ex. for 'LaTeX Error: Environment cslreferences undefined'" output: pdf_document: default bibliography: report.bib --- ```{r generate-bibtex-file, include=FALSE} knitr::write_bib(file = "report.bib", prefix = "") ``` # Used R

Printing UTF-8 characters in R, Rmd, knitr, bookdown

跟風遠走 提交于 2019-12-20 03:12:59
问题 UPDATE (April 2018): The problem still persists, under different settings and computers. I believe it is related to all UNICODE, UTF-8 characters. https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ PROBLEM: My Rmd/R file is saved with UTF-8 encoding. Other sessionInfo() details: Platform: x86_64-w64-mingw32/x64 (64-bit) LC_CTYPE=English_Canada.1252 other attached packages: [1]

R: rendering xtable

落爺英雄遲暮 提交于 2019-12-20 02:43:09
问题 I have an .Rmd file containing: ```{r, echo=FALSE, message=FALSE, results='asis'} library(xtable) print(xtable(groupGrundALL)) ``` Using the "Knit Word" button in RStudio it creates and opens a Word file, but only shows the following text line instead of the intended (rendered) table itself: % latex table generated in R 3.2.2 by xtable 1.7-4 package % Wed Oct 2111:14:28 2015 When I run in the console... library(xtable) print(xtable(groupGrundALL)) I get LaTeX code: % latex table generated in

citing references in a rmd file & error in pandoc-citeproc.exe

Deadly 提交于 2019-12-20 01:58:23
问题 This is my first time that I want to use citations in my rmd file and I don't know how can I do it exactly. I converted my rmd file to pdf document, but I have problem in generating reference and bibliography. I get this error while knitting: pandoc-citeproc.exe: Could not find bibliography.bib pandoc.exe: Error running filter pandoc-citeproc Filter returned error status 1 Error: pandoc document conversion failed with error 83 This is my yaml context: > title: "Context" > author: "Minoo" >

Automating the generation of preformated text in Rmarkdown using R

扶醉桌前 提交于 2019-12-20 01:58:17
问题 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

Why does 2nd ggplot not appear using knitr and grid?

前提是你 提交于 2019-12-19 20:34:45
问题 I am trying to create a document using knitr that includes ggplot2 plots modified using grid . In the example below, there should be 2 plots both using the diamonds dataset included in ggplot2 : the first one shows cut vs. color and the second shows cut vs. clarity. Instead, the later plot is repeated twice. The first plot is not generated in the figure directory at all. \documentclass{article} \begin{document} <<fig.cap = c('color', 'clarity')>>= library(ggplot2) library(grid) theme_update