Created
October 3, 2018 06:12
-
-
Save mczyzj/09d04567dd71110c4888a8b27f4681ef to your computer and use it in GitHub Desktop.
Citations in RMarkdown tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This snippets allows quick change from markdown citation syntax (i.e. @smith2018) to LaTeX syntax. | |
# It is particularly useful when you need to use both html and LaTeX output and don't want to use | |
# two separate tables for each output. In this case you can use simple conditional that changes RMarkdown | |
# syntax to LaTeX when needed. | |
df <- data.frame(book = c('Book one', 'Book two'), reference = c('@smith2005', '@foo2006') | |
dfR <- df$reference | |
dfR %>% | |
gsub('@', '', .) %>% | |
strsplit('; ') %>% | |
lapply(formatingCite) %>% | |
lapply(paste, collapse = '; ') %>% | |
unlist %>% | |
data.frame(references = .) %>% | |
bind_cols(df, .) %>% | |
select(-'reference') | |
dfR$references[dfR$references == '\\citeauthor{}, \\hyperlink{ref-}{\\citeyear{}}'] <- NA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For real life example please check templates in pestrPRA package