Citing within an RMarkdown table
Asked Answered
C

2

7

I am attempting to create a table which has citations built into the table. Here is a visual of what I am trying to achieve.

desired output

As far as I know you can only add footnotes in rowvars or colvars in kableExtra (love that package).

# Create a dataframe called df
Component <- c('N2','P3')
Latency <- c('150 to 200ms', '625 to 800ms')
Location <- c('FCz, Fz, Cz', 'Pz, Oz')
df <- data.frame(Component, Latency, Location)

Below is my attempt after reading through kableExtra's Git page

# Trying some code taken from the kableExtra guide
row.names(df) <- df$Component
df[1] <- NULL
dt_footnote <- df
names(dt_footnote)[1] <- paste0(names(dt_footnote)[2],
                                footnote_marker_symbol(1))

row.names(dt_footnote)[2] <- paste0(row.names(dt_footnote)[2], 
                                footnote_marker_alphabet(1))
kable(dt_footnote, align = "c", 
      # Remember this escape = F
      escape = F, "latex", longtable = T, booktabs = T, caption = "My Table Name") %>%
  kable_styling(full_width = F) %>%
  footnote(alphabet = "Jones, 2013",
           symbol = "Footnote Symbol 1; ",
           footnote_as_chunk = T)

Output

But this code only works on the headers. The ultimate goal would be if I could use a BibTex reference such as @JonesFunctionalMixedEffectModels2013 such that the final part of the code would look like

footnote(alphabet = @davidsonFunctionalMixedEffectModels2009,
           symbol = "Footnote Symbol 1; ", footnote_as_chunk = T)

Anyone have any ideas?

Thanks

Cerda answered 31/7, 2018 at 12:13 Comment(1)
I was not able to find a solution. I would suggest trying to contact the developer of kableExtra on his Git page if you are in need of a solution. I eventually just made the modification in Word after compiling the document. I am a big fan of the package because you are able to reduce the amount of code required to get a nice end result.Cerda
E
1

What I did at the end was to generate a temporary table with pander, then copy the references' number manually to my kable

pander(
  df,
  caption = "Temporal",
  style = "simple",
  justify = "left")
Emmittemmons answered 31/12, 2018 at 15:24 Comment(0)
D
0

It depends where you're writing (RStudio/ other IDE/ Overleaf) and what format you're using for the output (I assume pdf, but HTML is also an option).

I've been mainly using Quarto for my writing lately, so here's my attempt, but you should be able to adjust it to whatever format you need.

library(kableExtra)
library(knitr)

Component <- c('N2','P3')
Latency <- c('150 to 200ms', '625 to 800ms')
Location <- c('FCz, Fz[@wang_levetiracetam_2017], Cz[@roeske_modulation_2023]', 'Pz, Oz')
df <- data.frame(Component, Latency, Location)

table <- knitr::kable(df, format='simple')
kable_styling(table, full_width = F)

and this is what the output looks like for the whole PDF document:

Deflexed answered 13/8 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.