[R] getting package version inside .First.lib
Roger D. Peng
rpeng at jhsph.edu
Thu Jan 27 15:08:15 CET 2005
This is what I use for all my packages, which I believe handles multiple
versions of the same package being installed:
.First.lib <- function(lib, pkg) {
ver <- read.dcf(file.path(lib, pkg, "DESCRIPTION"), "Version")
ver <- as.character(ver)
...
}
-roger
Adrian Baddeley wrote:
> Greetings -
>
> Is it possible, inside .First.lib,
> to find out the version number of the package that is being loaded?
>
> If only one version of the package has been installed,
> we could scan the DESCRIPTION file, something like
>
> .First.lib <- function(lib, pkg) {
> library.dynam("spatstat", pkg, lib)
> dfile <- system.file("DESCRIPTION", package="spatstat")
> ttt <- scan(dfile, what="", sep="^M", quiet=TRUE)[2]
> vvv <- strsplit(ttt," ")[[1]][2]
> cat("spatstat version number",vvv,"\n")
> }
>
> but even this does not seem very safe (it makes assumptions about the
> format of the DESCRIPTION file).
>
> Is there a better way?
>
> thanks
> Adrian Baddeley
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/
More information about the R-help
mailing list