I am building my R package using Roxygen2
and devtools
, and I would like to add some citation information in my R
codes (i.e. I hope to write in a .R
file from which the citations can be auto-generated). The ultimate goal is to display, once I run the command citation(MyPkgName)
, the citations of the R package as well as the citation (preferrably with BibTeX entry) of the paper I submit. Is there a way to do that using devtools
? Thanks!
Asked
Active
Viewed 4,756 times
16

alittleboy
- 10,616
- 23
- 67
- 107
-
1It's not clear to me. Are you writing a package? Does creating a CITATION file not do what you want? – Dason May 12 '13 at 00:16
-
@Dason: yes, I am writing an R package and hope to include the citation information, but I don't know how to do that... – alittleboy May 12 '13 at 01:22
-
5Learn by [stealing from someone else](https://github.com/trinker/reports/blob/master/inst/CITATION). I personally break into Hadely and Dason's GitHub all the time to figure what to do with docuemntation. This file goes in your inst director. – Tyler Rinker May 12 '13 at 01:31
-
@TylerRinker: thanks a lot! I learned how to do that and put a CITATION file in the `inst` folder – alittleboy May 12 '13 at 06:00
-
Check out the Citations page of Hadley's [R Packages][http://r-pkgs.had.co.nz/inst.html] guide for more examples. – Tom Kelly Jun 02 '18 at 04:54
3 Answers
21
A file called "CITATION" needs to be created in the directory "yourPackage/inst/". The file CITATION
can be created automatically with
usethis::use_citation()
This file will contain an unfilled template with blank fields for citation information (e.g., author, journal, year, etc.) You need to fill in the gaps.

Lacey Etzkorn
- 55
- 5

epo3
- 2,991
- 2
- 33
- 60
19
The CITATION
file should be in the inst
directory. See the official documentation for details of what should be in the file.

csgillespie
- 59,189
- 14
- 150
- 185
2
Another way to include citation in your package is during attach time (e.g. when using library()
).
You can do so using the function .onAttach()
(it could go in a zzz.R
file, as suggested in Hadley's R Packages book).
One example, would be:
.onAttach<-function(libname, pkgname){
packageStartupMessage('Please cite this paper!')
}
But you can easily search for other examples in the net, as this one including a call to citation()
.

elcortegano
- 2,444
- 11
- 40
- 58
-
3I prefer if the packages do not print out unnecessary messages when being loaded. Providing information for citation() call is enough. – krassowski Dec 05 '20 at 10:05