Wolfgang Raffelsberger
2009-Mar-10 20:15 UTC
[R] require() is not giving TRUE / FALSE statements ?
Dear list, ?require says : "... |require| is designed for use inside other functions; it returns |FALSE| and gives a warning (rather than an error as |library()| does by default) if the package does not exist ..." However when I run the following code I don't get any TRUE / FALSE statements (but the warning only). Since I want to test from inside of a function if a given package is installed (and do some specific actions like eg trying to install if the answer is negative), I need the FALSE statement for use with if(). I found a work-around (see below), but I wanted to bring to your attention that require() doesn't give the message(s) it's supposed to return. Wolfgang > require(stats) > require(doesNotExist) # example for library that's not existing on my system Loading required package: doesNotExist Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'doesNotExist' >## After all I found a work-around with : >library(doesNotExist,logical.return=T) [1] FALSE Warning message: In library(doesNotExist, logical.return = T) : there is no package called 'doesNotExist' >## for completeness : > sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices datasets tcltk utils methods base other attached packages: [1] RODBC_1.2-4 svSocket_0.9-5 svIO_0.9-5 R2HTML_1.59 svMisc_0.9-5 svIDE_0.9-5 loaded via a namespace (and not attached): [1] tools_2.8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolfgang Raffelsberger, PhD Laboratoire de BioInformatique et G?nomique Int?gratives CNRS UMR7104, IGBMC 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 wolfgang.raffelsberger (at) igbmc.fr
Duncan Murdoch
2009-Mar-10 20:30 UTC
[R] require() is not giving TRUE / FALSE statements ?
On 10/03/2009 4:15 PM, Wolfgang Raffelsberger wrote:> Dear list, > > ?require says : > "... |require| is designed for use inside other functions; it returns > |FALSE| and gives a warning (rather than an error as |library()| does by > default) if the package does not exist ..." > > However when I run the following code I don't get any TRUE / FALSE > statements (but the warning only).You never printed the value, so you didn't see it. (It was returned marked invisible, i.e. not for printing.) Just save the value to a variable, or use it in a test, or explicitly print it: > print(require(stats)) [1] TRUE > print(require(doesNotExist)) Loading required package: doesNotExist [1] FALSE Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called 'doesNotExist' Duncan Murdoch> Since I want to test from inside of a function if a given package is > installed (and do some specific actions like eg trying to install if the > answer is negative), I need the FALSE statement for use with if(). I > found a work-around (see below), but I wanted to bring to your attention > that require() doesn't give the message(s) it's supposed to return. > > Wolfgang > > > require(stats) > > require(doesNotExist) # example for library that's not > existing on my system > Loading required package: doesNotExist > Warning message: > In library(package, lib.loc = lib.loc, character.only = TRUE, > logical.return = TRUE, : > there is no package called 'doesNotExist' > > >## After all I found a work-around with : > >library(doesNotExist,logical.return=T) > [1] FALSE > Warning message: > In library(doesNotExist, logical.return = T) : > there is no package called 'doesNotExist' > > > >## for completeness : > > sessionInfo() > R version 2.8.1 (2008-12-22) > i386-pc-mingw32 > > locale: > LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252 > > attached base packages: > [1] stats graphics grDevices datasets tcltk utils > methods base > > other attached packages: > [1] RODBC_1.2-4 svSocket_0.9-5 svIO_0.9-5 R2HTML_1.59 > svMisc_0.9-5 svIDE_0.9-5 > > loaded via a namespace (and not attached): > [1] tools_2.8.1 > > > > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . > Wolfgang Raffelsberger, PhD > Laboratoire de BioInformatique et G?nomique Int?gratives > CNRS UMR7104, IGBMC > 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France > Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 > wolfgang.raffelsberger (at) igbmc.fr > > ______________________________________________ > 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.
Apparently Analagous Threads
- alternatives to traditional least squares method in linear regression ?
- how to make a function recognize the name of an object/vector given as argument
- Problem with .libPaths & Rterm.exe (under Vista)
- error in mood.test
- optimizing speed of calculation (recursive product)