On Fri, Dec 11, 2009 at 9:41 AM, Achim Zeileis
<achim.zeil...@wu-wien.ac.at>wrote:

> On Fri, 11 Dec 2009, Rainer M Krug wrote:
>
>  Hi
>>
>> is there an easy and fast way, to generate a BibTeX file of all installed
>> /
>> loaded packages and R?
>>
>> I know about toBibtex(citation()) to extract the BibTeX for a single
>> package, but how can I generate a file containg citations for all
>> installed
>> / loaded packages?
>>
>
> I don't think that there is a way other than calling citation() for each of
> the installed.packages(). You could do something like this:
>
> ## try to get BibTeX for each of the installed packages
> b <- lapply(installed.packages()[,1], function(x)
>  try(toBibtex(citation(x))))
> ## omit failed citation calls
> b <- b[-which(sapply(b, class) == "try-error")]
> ## unify to list of Bibtex
> b <- lapply(b, function(x) if(inherits(x, "Bibtex")) list(x) else x)
> ## list of unique entries
> b <- unique(do.call("c", b))
> ## write everything to a single .bib file
> writeLines(do.call("c", lapply(b, as.character)), "Rpackages.bib")
>
>
Thanks a lot Achim. That works.

It would actually be nice, if the citation() function could take more then
one package name, and probably have an option to save the citations into a
BibTeX file.

Thanks,

Rainer



> hth,
> Z
>
>  Cheers,
>>
>> Rainer
>>
>> --
>> NEW GERMAN FAX NUMBER!!!
>>
>> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>> Biology,
>> UCT), Dipl. Phys. (Germany)
>>
>> Centre of Excellence for Invasion Biology
>> Natural Sciences Building
>> Office Suite 2039
>> Stellenbosch University
>> Main Campus, Merriman Avenue
>> Stellenbosch
>> South Africa
>>
>> Cell:           +27 - (0)83 9479 042
>> Fax:            +27 - (0)86 516 2782
>> Fax:            +49 - (0)321 2125 2244
>> email:          rai...@krugs.de
>>
>> Skype:          RMkrug
>> Google:         r.m.k...@gmail.com
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>


-- 
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:           +27 - (0)83 9479 042
Fax:            +27 - (0)86 516 2782
Fax:            +49 - (0)321 2125 2244
email:          rai...@krugs.de

Skype:          RMkrug
Google:         r.m.k...@gmail.com

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to