knitr

Character vector in R as itemized list with knitr

回眸只為那壹抹淺笑 提交于 2019-12-10 15:27:04
问题 I have a vector (e.g. letters ) that I want to incorporate into my .Rnw knitr document as an itemized list. How do I do this? I have tried \Sexpr{letters} but it merely places commas between each: a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z Something like this is just as unhelpful: \begin{itemize} \item[\Sexpr{letters}] \end{itemize} What is the proper way to do this? I'm looking for a result like: a b c d e f etc. 回答1: \documentclass{article} \begin{document}

Knitr escape latex special characters (e.g., ~, $) in R code

£可爱£侵袭症+ 提交于 2019-12-10 15:11:49
问题 LaTeX crashes when I run it on the output of this knitr document because the LaTeX special characters aren't properly escaped. Any hints how to fix this? \documentclass{beamer} \begin{document} \begin{frame}{Unescaped dollar signs and tildes} In this example, neither the tilde nor the dollar sign will appear in the pdf document, and the dollar sign will cause a \LaTeX error. <<xtable, results="asis">>= n <- 100 x <- rnorm(n) y <- 2*x + rnorm(n) out <- lm(y ~ x) library(xtable) xtable(summary

knitr: Knitting separate Rnw documents within an Rmd document

橙三吉。 提交于 2019-12-10 14:49:22
问题 I have a master R markdown document (Rmd) within which I would like to knit several separate Rnw documents (NO child documents) in one of the chunks. However, when I call knit on the Rnw document, the contained R code chunks do not seem to be processed, resulting in an error when trying to run texi2pdf on them. Illustration of the situation: Inside master. Rmd : ```{r my_chunk, echo=FALSE, message=FALSE, results='asis'} ... some code ... knit("sub.**Rnw**", output = ..., quiet = TRUE) tools:

Is there an easy way to run bash scripts on R Markdown, using Windows 10?

扶醉桌前 提交于 2019-12-10 14:47:35
问题 I've been learning R Markdown for the past months. It was fairly easy to get Anaconda Python to run within a R Markdown script, but I haven't yet found a way to get to run chunks of bash code within the same document. Using ```{bash} echo hello world ``` I get the error message /bin/bash: C:\Users\MyName\AppData\Local\Temp\Rtmp0MpNfS\chunk-code-4cbc213a3545.txt: No such file or directory Might any of you guys know what might be the root of this problem? 来源: https://stackoverflow.com/questions

Font size in ioslides markdown presentation title page

…衆ロ難τιáo~ 提交于 2019-12-10 14:46:29
问题 Trying to alter the default text size of the title page from an ioslides presentation but failing: --- title: "My title is a bit too long to fully fit on the title page. I would really like to alter the font size to provide a better fit. I have limited CSS skills to do so" author: "My Name" date: "29 March 2016" output: ioslides_presentation: css: slide.css --- ## R Markdown This is an R Markdown presentation. Where my style.css file is: h1 { font-size: 12px;} 回答1: First, spacing/indentation

R, knitr doesn't respect order of chunks and text

橙三吉。 提交于 2019-12-10 14:38:50
问题 Imagine I knit this Rnw file: \documentclass{article} \begin{document} Table1 <<example,results='asis', echo=FALSE>>= require(xtable) nn <- 15 mydata <- data.frame(A=1:nn,C=nn:1, C=runif(nn), D=rnorm(nn)) xtable(mydata, caption="Table1") @ Table2 <<example2,results='asis', echo=FALSE>>= xtable(mydata, caption="Table2") @ Table3 <<example3,results='asis', echo=FALSE>>= xtable(mydata, caption="Table3") @ \begin{obeylines} Just some text \end{obeylines} \end{document} It's a simple example that

r knit word document plots automatically re-sized

…衆ロ難τιáo~ 提交于 2019-12-10 14:33:59
问题 I am trying to add a plot to a word document. I would like the plot to maximize the area available when the page size is set to legal with narrow margins. I can set the fig.width and fig.height but it seems the plots get automatically re-sized to fit the default page size (letter) with normal margins. Here is a sample .rmd file that produces the same results: --- title: "plot-resize" output: word_document --- Plot with the height set to 3" and the width to 7.5": ```{r, echo = FALSE, fig

Build .md vignette using devtools

ε祈祈猫儿з 提交于 2019-12-10 14:22:42
问题 I’m using knitr::rmarkdown (but knitr::knitr does the same) as my VignetteEngine . I then build my package vignette using devtools::build_vignettes() . This works, but only creates HTML and R output files in inst/doc . What I want is a Markdown output file, since only that can be displayed directly within the Github project pages (for HTML files, Github shows the source and for Rmd files it shows a rendered output but — obviously — without executing the R blocks). I’ve tried finding out how

how to get output from a pipe connection before closing it in R?

空扰寡人 提交于 2019-12-10 14:18:57
问题 In R, we can open a pipe connection using pipe() and write to it. I observed the following situation that I do not quite understand. Let's use a python pipe for example: z = pipe('python', open='w+') cat('x=1\n', file=z) cat('print(x)\n', file=z) cat('print(x+2)\n', file=z) cat('print(x+2\n', file=z) cat(')\n', file=z) close(z) What I was expecting was the output from print() would be immediately shown in the R console, but the fact is the output comes only after I close the pipe connection:

How to split kable over multiple columns?

喜你入骨 提交于 2019-12-10 14:14:38
问题 I am trying to produce a "longitudinal" layout for long tables in RMarkdown with kable . For example, I would like a table to be split over two columns, like in the example below: dd <- data.frame(state=state.abb, freq=1:50) kable(list(state=dd[1:25,], state=dd[26:50,])) However, this hack produces an output that looks a way worse than the normal kable output (for example the header is not in bold). Is there a "proper" way to do this using kable ? 回答1: kable is a great tool, but has limits.