I'd like to create a report, but my report need to be start with a logo. In my example, I try to do :
Here is the .rmd file (say, cylinder.rmd)
---
```{r echo=FALSE, out.width = "30%", fig.align = "center"}
knitr::include_graphics("R_logo.png")
```
title: "cylinder_report"
author: "author_name"
date: "2023-01-25"
output: pdf_document
params:
cylinder: 0
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
df = mtcars
```
## Cylinder `r params$cylinder`
```{r output, echo=FALSE}
knitr::kable(df[df$cyl == params$cylinder,])
```
And my separated file is:
library(knitr)
library (rmarkdown)
data(mtcars)
cyls = unique(mtcars$cyl)
for(cyl in cyls) {
rmarkdown::render(
input = "cylinder.Rmd",
output_file = paste0("cylinder_report_", cyl),
params = list(cylinder = cyl)
)
}
#
This code doesn't work, but for better comprehension my desirable output must to be:
Please any help with it?
The solution was find in: https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html
The .Rmd needs to be:
---
title: "cylinder_report"
author: "author_name"
date: "2023-01-25"
output: pdf_document
params:
cylinder: 0
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}
\includegraphics[width=2in,height=2in]{R_logo.png}\LARGE\\}
- \posttitle{\end{center}}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
df = mtcars
```
## Cylinder `r params$cylinder`
```{r output, echo=FALSE}
knitr::kable(df[df$cyl == params$cylinder,])
```
Related
I am trying to knit a document using plotly to generate the images and rmarkdown. Below is a basic example:
---
title: "Test"
author: "Me"
date: "`r Sys.Date()`"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(plotly)
library(webshot)
library(webshot2)
```
## R Markdown
This is an R Markdown document. It is a test.
```{r test, echo=FALSE}
x <- seq(-1, 1, 0.1)
y <- dnorm(x, 0, 0.5)
pl1 <- plot_ly(x=x, y=y, type='scatter', mode='lines') %>%
config(mathjax='cdn') %>%
plotly::layout(
showlegend=TRUE,
legend=list(itemsizing='trace', orientation='h',
xanchor='center', x=0.5), margin=list(b=80, l=45, r=30, t=80),
title=list(text=
TeX("M \\text{ updates for } N=n=1 \\text{ for } P(update) = \\gamma_{i}.")))
# pl1
htmlwidgets::saveWidget(widget = pl1, file = "pl1.html")
webshot(url = "pl1.html", file = "pl1.pdf")
The problem is that when I knit the document, the htmlwidgets function generates the correct rendering of Latex (top image), but the webshot function does not (bottom image). Also, I have tried using fig.show='hold' but this doesn't help either.
I have also tried using webshot2 and, when using webshot I have installed webshot::install_phantomjs()
Trying to knit an Rmarkdown document to PDF from another R script. When I use the Rstudio interface, and hit Knit to PDF, it works perfectly fine and generates the PDF. But when I use the rmarkdown::render command, it gives me an error:
Markdown:
---
geometry: margin=0.75in
output:
pdf_document: default
params:
set_title:
value: "Sample"
editor_options:
chunk_output_type: console
header-includes:
\usepackage{fancyhdr}
\usepackage{graphicx}
---
---
title: `r params$set_title`
---
```{r load_libraries, include=FALSE, echo=FALSE}
suppressPackageStartupMessages({
library(knitr)
library(tidyverse)
library(kableExtra)
})
```
\addtolength{\headheight}{2.0cm}
\fancypagestyle{plain}{}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
```{r set_options, include = FALSE, echo = FALSE, warning = FALSE}
knitr::opts_chunk$set(comment = NA)
`%>%` <- dplyr::`%>%`
```
# 1. Table
```{r, echo = FALSE, message = FALSE, warning = FALSE}
# sample data frame
df <- data.frame(x = c("a", "b", "c"),
y = c("a", "b", "c"))
# print table
kableExtra::kable(df, booktabs = T) %>%
kable_styling(full_width = TRUE, font_size = 8) %>%
row_spec(0, bold = T) %>%
column_spec(1, width = "1cm") %>%
column_spec(2, width = "2cm")
```
This is how I am running it:
rmarkdown::render(input = "~/Projects/test.Rmd",
params = list(set_title = "TEMP"),
output_dir = "~/Desktop/",
output_file = "test.pdf")
Error:
! LaTeX Error: Environment tabu undefined.
Error: LaTeX failed to compile /Users/rathik/Projects/test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.
The error is due to using kableExtra::kable because when I remove that function call, the error goes away. Any ideas how to resolve it?
Thank you #Dirk, based on your suggestion and the LaTeX documentation, I added the following in the header and it seems to be working as expected:
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
I'm trying to create a table with rmarkdown and flextable where I am citing various works.
my Rmakrdown file:
---
title: "Innovative title"
author: "Vag Vaf"
date: '2021-12-29'
bibliography: references.bib
csl: apa-6th-edition.csl
output:
bookdown::word_document2:
fig_caption: yes
pdf_document:
toc: true
toc_depth: 2
citation_package: natbib
keep_tex: true
extra_dependencies: rotating, bookmark
fontsize: 12pt
geometry: margin=1in
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(fig.retina = 3, warning = FALSE, message = FALSE)
```
```{r studies-table}
studies.table <- tibble (
Authors = c("#Author1",
"#Author2"),
Area = c("Area1",
"Area2")
)
ft <- flextable(studies.table)
```
in my references.bib:
#article{Author1,
author = {Author, Solo},
journal = {Journal of Reproducible Examples},
pages = {1--18},
title = {{Yet another Test Title}},
volume = {1},
year = {2022}
}
#article{Author2,
author = {Author, Two and Author, Four},
journal = {Journal of Reproducible Examples},
pages = {75--82},
title = {{Awesome title}},
volume = {1},
year = {2022}
}
I am trying with this code, but #Author1 and #Author2 are not converted to the actual citation. They are displayed as #Aurthor1 and #Author2 in the table. Is there any way to indicate that this should be converted to a citation?
The package ftExtra is required for markdown syntaxes work in flextable cells:
```{r setup, include=FALSE}
library(easypackages)
packages(
"tidyverse",
"flextable",
"ftExtra"
)
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(fig.retina = 3, warning = FALSE, message = FALSE)
```
```{r studies-table}
studies.table <- tibble(
Authors = c(
"#Author1",
"#Author2"
),
Area = c(
"Area1",
"Area2"
)
)
flextable(studies.table) %>%
ftExtra::colformat_md()
```
I would like do add an icon to the text in one of the slides.
I've tried a few things but the end result is unstable. The icon are being printed in the html file, but If I add a slide or some text the the icons dissapear. Even if I revert what I've done with Ctrl+Z to previous working code the icons don't get printed...
I might be missing something, but the bookdown documentation didn't have anything on the subject...
---
title: 'Title'
author: "Author"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
ioslides_presentation:
self_contained: true
incremental: false
---
```{r knitr_init, echo=FALSE, message=FALSE, warning=FALSE, cache=FALSE}
## Global options
library(knitr)
library(shiny)
opts_chunk$set(
cache = FALSE,
prompt = FALSE,
tidy = FALSE,
comment = NA,
message = FALSE,
warning = FALSE
)
library(tidyverse)
library(plotly)
```
## S1
`r shiny::tags$i(class = "fa fa-arrow-down",style = "color: rgb(0,166,90)")`
item 3
`r shiny::tags$i(class = "fa fa-arrow-down",style = "color: rgb(0,166,90)")`
item 2
## S2
```{r, echo=F}
data.frame(a=1:10, b=1:10) %>%
plot_ly(x=~a,y=~b)
```
Writing the icons as <i class="fa fa-arrow-down" style="color: rgb(0,166,90)"></i> didn't seem to work either.
One option is to use the package icon (more information here).
---
title: 'Title'
author: "Author"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output:
ioslides_presentation:
self_contained: true
incremental: false
---
```{r knitr_init, echo=FALSE, message=FALSE, warning=FALSE, cache=FALSE}
## Global options
library(knitr)
library(shiny)
opts_chunk$set(
cache = FALSE,
prompt = FALSE,
tidy = FALSE,
comment = NA,
message = FALSE,
warning = FALSE,
echo=FALSE
)
library(tidyverse)
library(plotly)
library(icon)
```
## S1
```{r icon-style1}
icon_style(fontawesome("arrow-down", style = "solid"), scale = 2, fill = "#00A65A")
```
item 3
```{r icon-style2}
icon_style(fontawesome("arrow-down", style = "solid"), scale = 2, fill = "#00A65A")
```
item 2
## S2
```{r, echo=F}
data.frame(a=1:10, b=1:10) %>%
plot_ly(x=~a,y=~b)
```
-output
I just added two code chunks, one for each icon. Additionally, in your first r chunk, I added echo=FALSE to the opts_chunk$set and library(icon). In order to achieve the RGB color you chose, the HEX code was needed (#00A65A).
I want to have a figure caption, and right below it (on the next line), another piece of text. How can I do that?
I managed to do it with word_document output format:
---
title: "Untitled"
author: "Guilherme"
date: "10/6/2020"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, fig.cap="Título da figura \\\n Fonte: Autor"}
plot(1:10,1:10)
```
But it didn't work with bookdown::word_document2:
---
title: "test-report.Rmd"
author: "Guilherme"
date: "9 de maio de 2018"
output:
bookdown::word_document2:
fig_caption: TRUE
toc: TRUE
toc_depth: 4
number_sections: FALSE
---
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(
fig.path = "graficos/",
dpi = 100,
comment = NA,
warning = FALSE,
cache = FALSE,
echo = FALSE)
```
## Heading 2
And I have this next subsection
```{r, fig.cap="Título da figura \\\n Fonte: Autor"}
plot(1:10,1:10)
```