[R] Sweave, Bibtex, package references
Paolo Sonego
paolo.sonego at gmail.com
Tue Oct 28 18:07:36 CET 2008
Dear Thierry,
Thank you very much for you very useful advice!
I managed to solve my specific problem with this code:
<<echo=FALSE>>=
package <- grep("^package:", search(), value = TRUE)
keep <- sapply(package, function(x) x == "package:base" ||
!is.null(attr(as.environment(x), "path")))
package <- sub("^package:", "", package[keep])
pkgDesc <- lapply(package, packageDescription)
basePkgs <- sapply(pkgDesc, function(x) !is.null(x$Priority) &&
x$Priority == "base")
otherPkgs <- package[!basePkgs]
cite.by.name <- function(x){
res <- toBibtex(citation(x))
if (is.list(res)) res <- res[[1]]
res[1] <- sub("{",paste("{",x,sep=''),res[1],fixed=TRUE)
res
}
# suppressWarnings(cite.by.name("annotate"))
tmp <- sapply( otherPkgs, function(x) try( cite.by.name(x) ) )
for (i in 1:length(tmp)){
capture.output(tmp[[i]], file= "Rpackages.bib", append=T)
}
@
It does work, more or less, but still I need to write manually one by
one \nocite{otherPkgs[[1]]} \nocite{otherPkgs[[2]]} etc.
in order to pop up the references in the Bibliography section
\bibliographystyle{abbrv}
\bibliography{Rpackages}
Any idea how to automate this procedure?
Best Regards,
Paolo
ONKELINX, Thierry ha scritto:
> Dear Paolo,
>
> Have a look at this thread:
> http://www.nabble.com/Automating-citations-in-Sweave-td20128175.html#a20
> 128175
>
> HTH,
>
> Thierry
>
>
> ------------------------------------------------------------------------
> ----
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
> and Forest
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
> methodology and quality assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
> tel. + 32 54/436 185
> Thierry.Onkelinx a inbo.be
> www.inbo.be
>
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to
> say what the experiment died of.
> ~ Sir Ronald Aylmer Fisher
>
> The plural of anecdote is not data.
> ~ Roger Brinner
>
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of
> data.
> ~ John Tukey
>
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces a r-project.org [mailto:r-help-bounces a r-project.org]
> Namens Paolo Sonego
> Verzonden: dinsdag 28 oktober 2008 12:41
> Aan: R-List Help - use this to post
> Onderwerp: [R] Sweave, Bibtex, package references
>
> Dear all,
> I'm a big fan and happy user of the Sweave package for routine
> reporting.
> From inside a .Rnw script, I'd like to produce the references in bibtex
>
> format for each package loaded in the environment, write them in a .bib
> file and load them back from the
> \bibliography{bibliography} statement.
> Is this feasible?
> Any help would be greatly appreciated!
> Thanks in advance,
> Paolo
>
> ______________________________________________
> R-help a 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.
>
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
> en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
> door een geldig ondertekend document. The views expressed in this message
> and any annex are purely those of the writer and may not be regarded as stating
> an official position of INBO, as long as the message is not confirmed by a duly
> signed document.
>
More information about the R-help
mailing list