r-markdown

Referencing a 'hand-made' table using bookdown package

为君一笑 提交于 2019-12-04 01:54:02
I am trying to reference a table using the bookdown package. In the documentation the author only shows how to create tables using knitr::kable . ```{r table1} knitr::kable( head(iris, 20), caption = 'Here is a nice table!', booktabs = TRUE ) ``` Table \@ref(tab:table1) is here. Using knitr::kable works just fine. The caption of the table is displayed and I can reference the table. I would like to do the same with a classic hand-made markdown table but obviously the code below fails. What can I do to get a similar result as with the code above? ```{r table2, echo=FALSE, results='asis'} cat('|

Rmarkdown, Rstudio: pandoc.exe: Error producing PDF from TeX source

回眸只為那壹抹淺笑 提交于 2019-12-04 01:43:04
问题 I am trying to render a pdf document with the knit pdf button in RStudio, but I keep on getting this error: ! pdfTeX error (font expansion): auto expansion is only possible with scalable fonts. \AtBegShi@Output ...ipout \box \AtBeginShipoutBox \fi \fi l.167 pandoc.exe: Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 I know there is a lot be found on the internet regarding error 43, but non of them helped me. Does anyone know what it means exactly and

Embed Rmarkdown with Rmarkdown, without knitr evaluation

这一生的挚爱 提交于 2019-12-04 01:35:41
I want to demonstrate how to write RMarkdown, where said RMarkdown demonstration is embedded within an RMarkdown document used to create the course material. Within this fenced code block, I don't want knitr to execute the chunk. I want to put something like this into my "top level" Rmarkdown document, and have everything that's between the outer fences be printed verbatim in fixed width in the output HTML document, rather than having knitr evaluate the inner embedded R code chunk and inline code. ``` --- title: "RMarkdown teaching demo" author: "whoever" --- # Major heading Here's some text

Rmarkdown - Run code and display errors in document

本小妞迷上赌 提交于 2019-12-04 01:15:37
I get an error message when running the code below which is expected - I would like this to be ran and displayed in the pdf, however the error is returned in r and the code doesn't run. {r, warning=TRUE} library(survey) debug(withReplicates.svyrep.design) I have tried warning=TRUE but this doesn't work. How can I get the error displayed in the document? Add error=TRUE to the chunk options. That will result in the script running to completion with the error appearing in the output. 来源: https://stackoverflow.com/questions/34137797/rmarkdown-run-code-and-display-errors-in-document

Include code from an external R script, run in, display both code and output

帅比萌擦擦* 提交于 2019-12-04 00:26:06
Is it possible to include code from an external R script in an .Rmd and simultaneously run the code, display the code, and display its results in the output .HTML file? For example, if I have x <- 1 y <- 3 z <- x + y z in external.R . In the output document I want to see the code above along with the result of z , i.e. 4. Essentially, I want the equivalent of what would happen if I copy/pasted what's above in an R chunk. So I want ```{r} some.library::some.function("external.R") ``` to be the equivalent of ```{r} x <- 1 y <- 3 z <- x + y z ``` In the output HTML file. I've tried things like

How to wrap code and the output in markdown (.Rmd)

瘦欲@ 提交于 2019-12-04 00:25:09
In my documents in r parts I use long codes like: ```{r} output <- "very long query for example url to some website............................................." output ``` Is there any way not to make R wrap the code automatically, let's say after 60 characters? I tried tidy=TRUE, tidy.opts=list(width.cutoff=60) option but it doesn't work. And I want the same with output, because the output of my query is some text. I want to display the whole content in many lines, not just the begining in one line. How can I do it? Things have changed since 2015, but FWIW given that you are now using

Why does ggplot not allow suppressing of messages generated by its geoms?

谁说胖子不能爱 提交于 2019-12-04 00:17:17
问题 The geom_density_ridges geom from the ggridges package created ridgelines, and if a bandwidth is not specified, it attempts to find a sensible value. It then uses the base R message function to report that value (see https://twitter.com/ClausWilke/status/921363157553172480). The base R function suppressMessages function is designed to suppress such messages. For example, this code outputs a message: message('This is a message'); And this code outputs nothing: suppressMessages(message('This is

Aligning Columns with knitr kable function

青春壹個敷衍的年華 提交于 2019-12-04 00:14:46
问题 I am performing a simple task: creating a table and outputting it using R Markdown to pdf as follows: library(knitr) kable(datatable,align='ccccccc', col.names = c("Copy","Sigma Est","Sigma Lower","Sigma Upper", "Lambda Est","Lambda Lower","Lambda Upper"),digits=3) Problem when I output the table, columns are not centered. Actually, for some tables they are right aligned for others - left aligned, which seems rather random to me. Question How can I control the alignment of columns with R

German Umlaut characters in R markdown

烂漫一生 提交于 2019-12-04 00:06:05
问题 How can I display non-English characters in R-markdown? In an otherwise English document, I would like to render a single 'u' with two dots (an 'umlaut') on top of it. It is the correct spelling for 'u' in the name 'Muller.' 回答1: You can use standard HTML code for this. For example, the German letter ä can be displayed by placing the corresponding vowel after an ampersand sign, followed by uml; , i.e., ä . Here's an example of a .Rmd file: --- title: "Umlauts with Rmarkdown" output: html

Rotate a table from R markdown in pdf

本秂侑毒 提交于 2019-12-03 23:17:06
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(iris[1:5,]) ``` ``{r size='footnotesize', results='asis'} library(knitr) kable(iris[1:5,]) ``` ```{r