Dear list, How can I detect a package is installed or not? If not, then install it. For example, in a script, I want to check the package DESeq is installed or not. If not, then I will using this script to install it. source("http://www.bioconductor.org/biocLite.R") biocLite("DESeq") The pseudo script would be like this: try: library("DESeq") catch: source("http://www.bioconductor.org/biocLite.R") biocLite("DESeq") Thank you
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20110927/16f475fa/attachment.pl>
On Sep 27, 2011, at 3:19 PM, Fabrice Tourre wrote:> Dear list, > > How can I detect a package is installed or not? If not, then install > it. > > For example, in a script, I want to check the package DESeq is > installed or not. If not, then I will using this script to install it. > > source("http://www.bioconductor.org/biocLite.R") > biocLite("DESeq") > > The pseudo script would be like this: > > try: > library(Perhaps: if ( require("DESeq") ) { do-stuff } else { source("http://www.bioconductor.org/biocLite.R") biocLite("DESeq") } 'require' reports success or failure with a logical and loads the package if successful. You need to add logical.return=TRUE to a 'library' call to get avoid getting a character value back.> catch: > source("http://www.bioconductor.org/biocLite.R") > biocLite("DESeq") > > Thank you > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
On 11-09-27 3:19 PM, Fabrice Tourre wrote:> Dear list, > > How can I detect a package is installed or not? If not, then install it.Here's one way. This might be slow if you have all of CRAN installed, but it's quick enough if you only have a few dozen packages: installed <- rownames(installed.packages()) "DESeq" %in% installed Another way is to use if (!require("DESeq")) ... but that will give warnings if DESeq is not there. Duncan Murdoch> > For example, in a script, I want to check the package DESeq is > installed or not. If not, then I will using this script to install it. > > source("http://www.bioconductor.org/biocLite.R") > biocLite("DESeq") > > The pseudo script would be like this: > > try: > library("DESeq") > catch: > source("http://www.bioconductor.org/biocLite.R") > biocLite("DESeq") > > Thank you > > ______________________________________________ > R-help at 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.