knitr

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

回眸只為那壹抹淺笑 提交于 2021-01-27 07:43:18
问题 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

Is it possible to add vertical lines to tables produced with R knitr::kable in pdf?

荒凉一梦 提交于 2021-01-27 07:13:06
问题 I want to produce a table with knitr::kable with vertical lines on the borders and between certain columns. Is there a way to do it? My output document is pdf. Thanks! 回答1: Not too much clear, but maybe this could help: library(knitr) library(kableExtra) library(dplyr) dt <- mtcars[1:5, 1:6] dt %>% kable() %>% # here you can add the vertical line, in my example, for all the columns column_spec (1:7,border_left = T, border_right = T) %>% kable_styling() And if you need to save it as .pdf :

Is it possible to add vertical lines to tables produced with R knitr::kable in pdf?

痴心易碎 提交于 2021-01-27 07:12:25
问题 I want to produce a table with knitr::kable with vertical lines on the borders and between certain columns. Is there a way to do it? My output document is pdf. Thanks! 回答1: Not too much clear, but maybe this could help: library(knitr) library(kableExtra) library(dplyr) dt <- mtcars[1:5, 1:6] dt %>% kable() %>% # here you can add the vertical line, in my example, for all the columns column_spec (1:7,border_left = T, border_right = T) %>% kable_styling() And if you need to save it as .pdf :

knitr kable: Text color in PDF from RNW is grey

↘锁芯ラ 提交于 2021-01-27 07:05:52
问题 When I create a table using the knitr::kable function within a RNW file, the text color of the table items in the PDF appears to be grey. I would like to change this to black. How can I do this? 回答1: \documentclass{article} \begin{document} <<>>= knitr::kable(cars[1:10,]) # grey @ <<results="asis">>= knitr::kable(cars[1:10,]) # black @ \end{document} By default, the output of kable will be wrapped in a knitrout environment where the text color ( fgcolor ) is set to grey ( rgb: 0.345, 0.345, 0

Access name of .rmd file and use in R

自闭症网瘾萝莉.ら 提交于 2021-01-27 06:21:09
问题 I am knitting a markdown file called MyFile.rmd . How can I access the string MyFile during the knitting and use it for: use in the title section of the YAML header? use in subsequent R chunk? --- title: "`r rmarkdown::metadata$title`" author: "My Name" date: "10. Mai 2015" output: beamer_presentation --- ## Slide 1 ```{r} rmarkdown::metadata$title ``` leads to... ... which is incorrect as the file I am knitting is named differently. > sessionInfo() R version 3.1.2 (2014-10-31) Platform: x86

Wrapping plots in another html container within an Rmd file

你离开我真会死。 提交于 2021-01-27 04:36:07
问题 I have a situation where, for display purposes, I need to wrap an outputted plot in a <div> container. At the most basic level, this is what I would like to do: ```{r fig.width=7, fig.height=6,results='asis',echo=FALSE} cat('<div>') plot(cars) cat('</div>') ``` However, the output document looks like this: ![plot of chunk unnamed-chunk-2](figure/unnamed-chunk-2.png) Is there a workaround if you need to "wrap" output? The same behaviour only seems to occur when it's wrapping the plot.

Error in object[seq_len(ile)] : object of type 'symbol' is not subsettable

这一生的挚爱 提交于 2021-01-26 20:32:01
问题 I am trying to convert an rmd file to pdf using render statement. render("MiningReport.Rmd", "pdf_document",output_dir = "C:/ProjectSocial/Reports/Twitter/Maybelline") I am getting an error as below Quitting from lines 109-113 (MiningReport.Rmd) Error in object[seq_len(ile)] : object of type 'symbol' is not subsettable This looks very strange to me because when I knit the Rmd file then is no such error and the pdf report is generated successfully and when I try to do the same using render

Error in object[seq_len(ile)] : object of type 'symbol' is not subsettable

大憨熊 提交于 2021-01-26 20:30:10
问题 I am trying to convert an rmd file to pdf using render statement. render("MiningReport.Rmd", "pdf_document",output_dir = "C:/ProjectSocial/Reports/Twitter/Maybelline") I am getting an error as below Quitting from lines 109-113 (MiningReport.Rmd) Error in object[seq_len(ile)] : object of type 'symbol' is not subsettable This looks very strange to me because when I knit the Rmd file then is no such error and the pdf report is generated successfully and when I try to do the same using render

Prevent pagebreak in kableExtra landscape table

偶尔善良 提交于 2021-01-26 17:31:58
问题 How can a landscape table be plotted in R Markdown (PDF output) without causing a page break to be inserted? There is the function landscape from the kableExtra package, but this forces a page break to be inserted. Example: The normal behaviour for tables in R Markdown is that the will float to minimise the breaking up of text. --- output: pdf_document --- Some Text ```{r, echo=F, warning=F} library(kableExtra) knitr::kable(mtcars, format = "latex", caption = "A table") ``` More Text

Prevent pagebreak in kableExtra landscape table

荒凉一梦 提交于 2021-01-26 17:28:00
问题 How can a landscape table be plotted in R Markdown (PDF output) without causing a page break to be inserted? There is the function landscape from the kableExtra package, but this forces a page break to be inserted. Example: The normal behaviour for tables in R Markdown is that the will float to minimise the breaking up of text. --- output: pdf_document --- Some Text ```{r, echo=F, warning=F} library(kableExtra) knitr::kable(mtcars, format = "latex", caption = "A table") ``` More Text