knitr

Bookdown does not render image in output pdf

牧云@^-^@ 提交于 2021-01-29 14:09:43
问题 I'm trying to include an image in the example index.rmd file that comes with the bookdown-package within RStudio. (New Project -> Book Project using bookdown) I then simply appended the following code within an R code-chunk. ```{r} knitr::include_graphics("png_logo.png") ``` Running the code chunk on its own produces the expected output (shows figure). However, if I use the following command in the terminal: bookdown::render_book("index.Rmd", "bookdown::pdf_book") a pdf-file is produced, that

knitr cuts off coord_fixed ggplot

醉酒当歌 提交于 2021-01-29 06:50:29
问题 I'm experiencing some behavior where knitr cuts off part of a ggplot2 image when i used coord_fixed(ratio = 1) . mwe.Rmd --- title: "mwe" output: pdf_document --- ```{r} library(ggplot2) data <- list( x1 = 0:6, y1 = 0, x2 = rep(0:6, 2), y2 = rep(c(0, 1), each = 7) * -1, labels = paste("Label", 1:7) ) g <- ggplot() + geom_text(aes(0:6, 0.75), label = data$labels) g_unfixed_1 <- g + geom_raster(aes(data$x1, data$y1)) g_fixed_1 <- g_unfixed_1 + coord_fixed(ratio = 1) g_unfixed_2 <- g + geom

How to export an xtable as PDF directly via R script?

扶醉桌前 提交于 2021-01-28 13:55:08
问题 I have a data.frame that I need as a nice PDF table for a scientific poster. While it's very easy to export plots via pdf() , I'm stuck with this table. I know how to get a PDF table with rmarkdown, e.g. --- output: pdf_document --- ```{r tab, echo=FALSE, results='asis'} library(xtable) xtable(head(mtcars)) ``` But I want this output directly from the R script, e.g. renderThisToPDF(xtable(head(mtcars), to="nicetable.pdf") # fantasy code How would I do this? So far I attempted this code with a

R gt package: error in latex (“there's no line here to end”)

半腔热情 提交于 2021-01-28 12:40:32
问题 I am trying to include a table generated with the gt() function in a tex file. I create a .Rnw file, then weave it with knitr and compile with pdflatex. During compilation I get an error: "there no line here to end", caused by a newline inserted by gt() in the table header. This is a MWE: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{booktabs} \usepackage{longtable} \usepackage{caption} \begin{document} <<setup, include=FALSE>>= library(knitr) library(tidyverse) library(gt)

Rotating a table in PDF output from RMarkdown with more than one page

半腔热情 提交于 2021-01-28 12:01:18
问题 I want to rotate a wide table in my PDF output. I came across this fantastic question, but my table is longer. When I copy/paste one of the examples shown in that question, it works nice using RMarkdown. library(kableExtra) kable(iris[1:5,], format = "latex", booktabs = TRUE) %>% kableExtra::landscape() However, if we remove the subsetting we see that the table exceeds the dimension of the page. library(kableExtra) kable(iris, format = "latex", booktabs = TRUE) %>% kableExtra::landscape() So

Rnotebook not showing code output for data frames

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 03:16:29
问题 My code chunk output in Rnotebook is not appearing (as if not being run) when I try to view data frame results. I have to pass it through the pander() function to see the output print out. Is this something to do with knitr? I mention this because I set the options at the beginning to the following: ```{r setup, include = FALSE} knitr::opts_chunk$set(echo = TRUE, eval = TRUE) ``` I have tried setting the options directly in the chunk but get the same unwanted result. Is there a setting I am

Changing the latex_engine gets an error when trying to align images on kable

元气小坏坏 提交于 2021-01-28 02:22:16
问题 I am trying to copy the first answer in this question. The answer really meets what I wanted. But it get an error when the latex_engine is xelatex. But I really needs to show the output in chinese. Here's the code --- title: "Untitled" output: pdf_document: latex_engine: xelatex --- This example highlights the issue I am having with formatting a nice table with the graphics and the vertical alignment of text. ```{r echo=FALSE, results='hide', warning=FALSE, message=FALSE} ## Load modules

cannot knit PDF in R studio

二次信任 提交于 2021-01-27 17:51:16
问题 I am totally new to RStudio and I was working on an RMarkdown document. When I click on Knit PDF , and I keep getting the result like this: output file: A1-soln-template__2__molly.knit.md ! Package inputenc Error: Unicode char μ (U+3BC) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H for immediate help. ... l.142 null hypothesis: Ho:μ Try running pandoc with --latex-engine=xelatex. pandoc: Error producing PDF Error: pandoc document

cannot knit PDF in R studio

让人想犯罪 __ 提交于 2021-01-27 17:16:52
问题 I am totally new to RStudio and I was working on an RMarkdown document. When I click on Knit PDF , and I keep getting the result like this: output file: A1-soln-template__2__molly.knit.md ! Package inputenc Error: Unicode char μ (U+3BC) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H for immediate help. ... l.142 null hypothesis: Ho:μ Try running pandoc with --latex-engine=xelatex. pandoc: Error producing PDF Error: pandoc document

How to “box” the output of “summary()” in Rmarkdown

心已入冬 提交于 2021-01-27 07:43:32
问题 I have seen this post: How to create R-markdown sections inside a R code chunk? With proper code display and one of the responders, Cedric, impressed me with the way he or she boxed the output of summary() command in R. I understand that the user used Sweave to create such a great output. I am curious that whether there is a way to use Knit to output to a PDF file in the similar fashion. Thank you! 回答1: There's nothing special about Sweave vs. R Markdown here. You can copy and paste the LaTeX