On 12/03/2011 06:04 AM, Hadley Wickham wrote:
Hi all,
I was wondering if any one had scripts that they could share for
capturing the current version of R packages used for a project. I'm
interested in creating a project local library so that you're safe if
someone (e.g. the ggplot2 author) updates a package you're relying on
and breaks your code. I could fairly easily hack together, but I was
wondering if any one had any neat scripts they'd care to share.
Hi Hadley,
This makes quite a few assumptions, but I would build a list of packages
called in R scripts:
# get all calls to library or require in a subdirectory of scripts
packagestrings<-c(system("grep library *.R",intern=TRUE),
system("grep require *.R",intern=TRUE))
# get the unique package names
packagenames<-unique(sapply(strsplit(packagestrings,"[()]"),"[",2))
# get the information on all installed packages in the system
installedpackages<-installed.packages()
# get the indices of the packages used in the subdirectory
whichpackages<-which(match(rownames(installedpackages),packagenames,0)>0)
# get the version information for each used package
installedpackages[whichpackages,"Built"]
Jim
______________________________________________
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.