Reputation: 1035
In Rmarkdown file, how to import all the *.bib files in a directory for bibliography?
I have the following file tree
./
./the_Rmd_file_in_question.Rmd
./includes/
./includes/x.bib
./includes/y.bib
...
The followings don't work.
bibliography:
- ./includes/*.bib
or
bibliography:
`r library(stringr); str_replace(list.files(path = './report/includes/', pattern = '^.+\\.bib$', full.names = TRUE), pattern = './\\w+/', replacement = './')`
Upvotes: 2
Views: 307
Reputation: 44788
You can do this, but it's a little tricky. What Pandoc wants to see in the bibliography
field is something like
bibliography: ["file1.bib", "file2.bib"]
I can get that with this code:
bibliography: ["`r paste(c('file1.bib', 'file2.bib'), collapse='\",\"')`"]
Given your updated structure of the directory, I think this should work:
bibliography: ["`r paste(list.files(path = './includes', pattern = '^.+\\.bib$', full.names = TRUE), collapse='\",\"')`"]
The list.files()
call will give you usable names, you don't need to modify it.
Upvotes: 3