Citing inside the cell of flextable - r

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()
```

Related

Start rmarkdown report with logo image

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,])
```

RMarkdown Change numbering for tables in PDF document

I want to change the numbering of the tables in the RMarkdown document so that all tables in the appendix have an "A-" in front of the number, thus: "Table A-2".
Only in the appendix. Otherwise with normal numbering ("Table 1").
However, I am not really getting anywhere.
Here is my reproducible example:\
---
title: "This is my title"
date: "`r Sys.setlocale(locale = 'English') ; format(Sys.time(), '%B %d, %Y')`"
output: pdf_document
---
```{r echo = F, message = F, warning = F}
library(tidyverse)
library(knitr)
``` #The hash mark must be removed!
# Results
```{r echo = F, message = F, warning = F}
tribble(~column1, ~column2,
"value1", 2,
"value2", 5
)%>%
kable(booktabs=T, caption = "This is the caption of the first table")
```
# Appendix
```{r echo = F, message = F, warning = F}
tribble(~column1, ~column2,
"value1", 6,
"value2", 8
)%>%
kable(booktabs=T, caption = "This is the caption of the second table")
```
This is really a LaTeX question, and I found the answer here.
You add these LaTeX lines after your Appendix title:
\setcounter{table}{0}
\renewcommand{\thetable}{A\arabic{table}}

Adding icons to text unstable

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).

How to break a line in fig.cap in rmarkdown (bookdown) to docx?

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)
```

how to make a multiple line table with xtable, longtable

I am trying to to use xtable() and the longtable environment to display a multi=page table.
Currently when you run the code it will show "\scalebox " at the top and then it will cutoff columns of the table.
How do you remove the "\scalebox" at the top and show all the column in a readable manner?
Thank you.
here is the code:
---
title: "test"
output: pdf_document
keep_tex: TRUE
setspace: singlespacing
geometry: margin=1.1cm
header-includes:
- \usepackage{color}
- \usepackage{amsmath}
- \usepackage{xcolor}
- \usepackage{colortbl}
- \usepackage{tabulary}
- \usepackage{tabularx}
- \usepackage{longtable}
- \usepackage{ltxtable}
fig.lp: ('';character)
fig.pos: "H"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE , comment = NA, message= FALSE, warning = FALSE)
```
```{r one, include= FALSE}
n=600
table = data.frame(name = rep(" dakjf aslkj dklsfj aslj ldjs",n),
NUMERICFIELDNUMBERa = rep(10000,n),
NUMERICFIELDNUMBERb = rep(10000,n),
NUMERICFIELDNUMBERc = rep(10000,n),
NUMERICFIELDNUMBERd = rep("1250 + 52.33",n),
NUMERICFIELDNUMBERe = rep("25.6 + 36.25",n),
NUMERICFIELDNUMBERf = rep(10000,n),
NUMERICFIELDNUMBERg = rep(10000,n)
)
head(table)
colnames(table) = c("GROUP NAME",
"Numeric Field Number1",
"Numeric Field Number2",
"Numeric Field Number3",
"Numeric Field Number4",
"Numeric Field Number5",
"Numeric Field Number6",
"Numeric Field Number7"
)
rownames(table) = NULL
```
```{r echo= FALSE, comment = FALSE, message= FALSE, warning = FALSE, results='asis'}
library(xtable)
options(xtable.include.rownames=F)
options(xtable.scalebox=.7)
#options(xtable.tabular.environment = "tabulary")
#options(xtable.width = "7in")
options(xtable.comment=F)
options(xtable.floating = F)
t = xtable(table)
#align(t)= "cccccccc"#"cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}cp{2cm}" #rep("p{2cm}C",8)#"p{1cm}cccccccc"
#align(t) = "cp{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}"
print(t, sanitize.text.function = identity)
```

Resources