knitr

How to knit directly to R object?

廉价感情. 提交于 2019-12-12 12:44:05
问题 I'd like to store a knit() ted document directly in R as an R object, as a character vector . I know I can do this by knit() ing to a tempfile() and then import the result, like so: library(knitr) library(readr) ex_file <- tempfile(fileext = ".tex") knitr::knit(text = "foo", output = ex_file) knitted_obj <- readr::read_file(ex_file) knitted_obj returns # [1] "foo\n" as intended. Is there a way to do this without using a tempfile() and by directly "piping" the result to a vector? Why on earth

wrap text in knitr::kable table cell using “\n”

只愿长相守 提交于 2019-12-12 12:24:22
问题 How can I wrap a cell in a knitr::kable table cell using \n ? I want to generate a .rmd file containing some tables where one column needs text wrapping. The places where the wrapping should occur are marked with \n . I tried (this is a standalone .rmd document): --- output: pdf_document --- ## A Table with text wrap ```{r cars} knitr::kable(data.frame(col1 = c("a", "b"), col2 = c("one\ntwo", "three\nfour"))) ``` ..but this doesn't work. Instead of staying in col2 , the wrapped part lives on

Incorrect conversion from R Markdown to LaTeX

懵懂的女人 提交于 2019-12-12 11:41:44
问题 Why does the following R Markdown minimal (non)-working example not compile to PDF? --- header-includes: - \usepackage{fancyhdr} - \pagestyle{fancy} - \lhead{} - \chead{} - \rhead{The performance of new graduates} - \lfoot{From: K. Grant} - \cfoot{To: Dean A. Smith} output: pdf_document: keep_tex: yes latex_engine: xelatex --- # Test In particular, the problematic conversion happens to -\lfoot{From: K. Grant} and -\cfoot{To: Dean A. Smith} , as seen in the output .tex file: \usepackage

using webshot within knitr

与世无争的帅哥 提交于 2019-12-12 11:38:51
问题 In the process of trying to find a solution to this SO question about saving a heatmap produced by d3heatmap , I encountered an unrelated problem using webshot within the development version of knitr (HT: hrbrmstr). library(devtools) devtools::install_github('yihui/knitr', build_vignettes = TRUE) library(knitr) After installing and loading the development version of knitr , I tried running the following .Rmd file: --- title: "Untitled" output: pdf_document --- ```{r} library(d3heatmap)

Rstudio knit pdf in Rstudio loadNamespace(name): there is no package called 'rmarkdown'

纵然是瞬间 提交于 2019-12-12 10:47:45
问题 I just updated to Rstudio Version 0.98.1074. When I try to use compile notebook with a script or Knit pdf with an .rmd I get Error in loadNamespace error: there is no package called 'rmarkdown' yet I can type rmarkdown::render("filename.rmd") and it will render the document. I removed rmarkdown and re-installed with RStudio and it did not help. I've updated all my packages and I'm using R3.1.1. This is a minor inconvenience since I have a workaround but thought I'd post in case there is a

Using knitr (from .Rhtml to html): how to embed a link in an R Figure?

自闭症网瘾萝莉.ら 提交于 2019-12-12 10:47:35
问题 I am using knit to convert my .Rhtml file to an .html file. I am calling the output of a chunk called Q1: <!--begin.rcode Q1,echo=FALSE,fig.show="all",fig.align="center",warning=FALSE end.rcode--> Here comes the chunk, it is basically a ggplot2 figure in a 2x2 layout. library(ggplot2) myplot = list() for (i in 1:4){ x = 1:100 y = sample(100,100) data = data.frame(x=x,y=y) myplot[[i]] = ggplot(data,aes(x=x,y=y))+geom_point()+labs(title="bla")} do.call(grid.arrange,c(myplot,list(nrow=2,ncol =2)

Why are plotly-rendered graphs not working on Mozilla

馋奶兔 提交于 2019-12-12 09:58:26
问题 I am getting the following error when trying to open an html document put together with knitr in Mozilla Firefox. The error is a result of the graph element composed with the plotly package. unknownError: error occurred while processing 'getCachedMessages: out of memory The entire contents of the rmarkdown file (default everything else): library(plotly) library(ggplot2) theData <- data.frame(A=1:26, B=letters, C=rnorm(26,19)) g<-ggplot(theData, aes(x=A, y=C)) + geom_point() ggplotly(g) I have

Knitr - stop superscript in R Markdown

橙三吉。 提交于 2019-12-12 09:43:46
问题 I need to stop superscript before comma - , or full stop - . . When converting the Rmd file to HTML knitr makes comma superscripted as well. Example: example.Rmd MyTitle ======================================================== J.Smith^1, K.John^2, H.Gone^*. example.html Let me know if this was asked before, I can't find relevant questions. 回答1: You may insert HTML tags directly to Markdown documents. To toggle the "superscripting" mode, use sup . MyTitle ======================================

Rotate a table from R markdown in pdf

拈花ヽ惹草 提交于 2019-12-12 08:22:56
问题 I'm writing in R Markdown and have a contingency table that is quite wide. I am converting the R markdown document to a PDF using pandoc. Is it possible to rotate or shrink the table? Ideally this would be done without having to switch to LaTeX formatting. My Attempts: I've been abusing the figure options in knitr to attempt this, but whether I use kable or xtable, I haven't had any luck. Some permutations I have tried include: ```{r out.extra='angle=90', results='asis'} library(knitr) kable

How to rotate one plot out of many when using knitr?

冷暖自知 提交于 2019-12-12 07:32:06
问题 I am using knitr with plots. I would like to rotate one of them 90 degree. For example: \documentclass{article} \begin{document} <<cache=TRUE, echo=FALSE, message=FALSE, warning=FALSE, comment=NA, eval=TRUE, results=asis>>= library("ggplot2") library("gridExtra") func <- function(data,x,y) { p1 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point() p2 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point() p3 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point() p4 <-