Closed huizezhang-sherry closed 2 years ago
Very good idea! I'll add this to ctv
and then report here...
I looked at this a little bit now and remembered why we don't have such a function yet: There is no natural candidate for an extractor or coercion function to which we could add a ctv
method. There are only bibentry()
and citation()
but both of these are not generic. And there are no coercion functions like as.bibentry()
or as.citation()
. I didn't have an idea for a readily available generic we could use here, yet.
So for the moment I create a new generic in the code below. I'm not sure yet how to best include it in the ctv
package.
as.bibentry <- function(x, ...) {
UseMethod("as.bibentry")
}
as.bibentry.ctv <- function(x, ...) {
utils::bibentry(
bibtype = "Manual",
author = as.person(x$maintainer),
title = paste0("{CRAN} Task View: ", x$topic),
url = paste0("https://CRAN.R-project.org/view=", x$name),
year = substr(x$version, 1, 4),
note = paste0("Version ", x$version)
)
}
as.bibentry.ctvlist <- function(x, ...) {
do.call("c", lapply(x, as.bibentry))
}
With this code you can convert individual ctv
task views into bibentry
objects which in turn can be converted to BibTeX:
a <- available.views()
as.bibentry(a$Econometrics)
## Zeileis A, McDermott G, Tappe K (2022). _CRAN Task View: Econometrics_.
## Version 2022-04-11, <URL: https://CRAN.R-project.org/view=Econometrics>.
toBibtex(as.bibentry(a$Econometrics))
## @Manual{,
## author = {Achim Zeileis and Grant McDermott and Kevin Tappe},
## title = {{CRAN} Task View: Econometrics},
## url = {https://CRAN.R-project.org/view=Econometrics},
## year = {2022},
## note = {Version 2022-04-11},
## }
And the same works for ctvlist
objects:
as.bibentry(a)
## Park JH, Cameletti M, Pang X, Quinn KM (2022). _CRAN Task View:
## Bayesian Inference_. Version 2022-04-06, <URL: https://CRAN.R-project.org/view=Bayesian>.
##
## Mullen K (2022). _CRAN Task View: Chemometrics and Computational
## Physics_. Version 2022-03-07, <URL: https://CRAN.R-project.org/view=ChemPhys>.
##
## Zhang W, Zhang R, Zhang E (2021). _CRAN Task View: Clinical Trial
## Design, Monitoring, and Analysis_. Version 2021-12-29, <URL:
## https://CRAN.R-project.org/view=ClinicalTrials>.
##
## ...
I would love to see this added!
On a somewhat related note, is it possible to have DOIs assigned to each CTV?
My understanding is that a DOI should resolve to the same content it was registered for - whereas here we want to link to the same stable URL whose content is changing rather frequently. And previous versions are only kept in the source repository but not on CRAN. That's why we don't have DOIs and just the stable CRAN URLs.
I've thought a bit more about this and decided not to introduce a new generic as.bibentry()
in the ctv
package for now. This should really be in utils along with the bibentry()
class. But given that R 4.2.0 was just released we will have to wait for this for quite a while.
So instead I've included a citation
element in each ctv
object that can be extracted with $citation
. Furthermore, to facilitate accessing individual CRAN task views (as opposed to the list of all available CRAN task views) there is a new function ctv()
in the development version of the package on R-Forge. With this you can do:
install.packages("ctv", repos = "https://R-Forge.R-project.org")
library("ctv")
ctv("Econometrics")
## CRAN Task View
## --------------
## Name: Econometrics
## Topic: Econometrics
## Maintainer: Achim Zeileis, Grant McDermott, Kevin Tappe
## Contact: Achim.Zeileis@R-project.org
## Version: 2022-04-11
## Repository: https://CRAN.R-project.org/
## [...]
ctv("Econometrics")$citation
## To cite the Econometrics task view in publications use:
##
## Zeileis A, McDermott G, Tappe K (2022). _CRAN Task View:
## Econometrics_. Version 2022-04-11,
## <https://CRAN.R-project.org/view=Econometrics>.
##
## A BibTeX entry for LaTeX users is
##
## @Manual{,
## author = {Achim Zeileis and Grant McDermott and Kevin Tappe},
## title = {CRAN Task View: Econometrics},
## year = {2022},
## note = {Version 2022-04-11},
## url = {https://CRAN.R-project.org/view=Econometrics},
## }
Given that this received some thumbs up and no complaints, I'm closing this issue. This will be released in the next CRAN version of the package.
Absolute amazing work to get the CRAN task view more visible on GitHub!
I see there is a citation line in each ctv page and am thinking a function similar to
citation("...")
can be handy to generate the bibtex for citing ctvs.