[R] require() is not giving TRUE / FALSE statements ?
Wolfgang Raffelsberger
wraff at titus.u-strasbg.fr
Tue Mar 10 21:15:45 CET 2009
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
More information about the R-help
mailing list