require(..., quietly=TRUE) does not suppress warning

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

require(..., quietly=TRUE) does not suppress warning

Dan Tenenbaum-2
Hi,

The `quietly` argument of `require` is documented as follows:

 quietly: a logical.  If ‘TRUE’, no message confirming package
          attaching is printed, and most often, no errors/warnings are
          printed if package attaching fails.

However:

> require(foo, quietly=TRUE)
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘foo’

Am I misreading the docs or is R misbehaving?

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Dan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: require(..., quietly=TRUE) does not suppress warning

John Nolan-2
Well, it says "most often" no errors/warnings are given, so it is not contradicting the docs!   It looks like the person/team that coded  require( ) decided you should get an error when the package doesn't exist.

If you want a silent loading, consider
     aaa <- try( library(foo,verbose=FALSE,quietly=TRUE),silent=TRUE)
and then check to see if aaa is of class "try-error" and check for failure

John
………………………………………………………………………………..

John P. Nolan
Math/Stat Dept., American University
Gray Hall, 4400 Massachusetts Ave, NW
Washington, DC 20016-8050
Phone: 202-885-3140
E-mail:  [hidden email]
Web:   http://fs2.american.edu/jpnolan/www/



-----Original Message----
From: R-devel [mailto:[hidden email]] On Behalf Of Dan Tenenbaum
Sent: Thursday, December 8, 2016 2:43 PM
To: R-devel <[hidden email]>
Subject: [Rd] require(..., quietly=TRUE) does not suppress warning

Hi,

The `quietly` argument of `require` is documented as follows:

 quietly: a logical.  If ‘TRUE’, no message confirming package
          attaching is printed, and most often, no errors/warnings are
          printed if package attaching fails.

However:

> require(foo, quietly=TRUE)
Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘foo’

Am I misreading the docs or is R misbehaving?

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS Sierra 10.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Dan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: require(..., quietly=TRUE) does not suppress warning

Dan Tenenbaum-2
Well, I'm getting a warning (not an error) when the package doesn't exist.
I interpreted "most often" to mean that suppressing warnings/errors is why you'd most often use this argument, as most packages don't emit startup messages.

And technically there isn't a problem with attaching the package, since we don't even try to attach packages that don't exist.

So yes, very careful parsing of the docs suggests that the behavior is correct, but it does seem to violate the 'spirit' of what a user might expect. I am pretty sure I have used the 'if (!require("pkg")) install.packages("pkg")' pattern before without seeing this warning, so I wondered if the behavior had changed, and that's what prompted me to write.

I know I can squelch the warning by wrapping the require() in suppressWarnings().

Dan


----- Original Message -----
> From: "John P. Nolan" <[hidden email]>
> To: "Dan Tenenbaum" <[hidden email]>, "R-devel" <[hidden email]>
> Sent: Thursday, December 8, 2016 12:37:02 PM
> Subject: RE: require(..., quietly=TRUE) does not suppress warning

> Well, it says "most often" no errors/warnings are given, so it is not
> contradicting the docs!   It looks like the person/team that coded  require( )
> decided you should get an error when the package doesn't exist.
>
> If you want a silent loading, consider
>     aaa <- try( library(foo,verbose=FALSE,quietly=TRUE),silent=TRUE)
> and then check to see if aaa is of class "try-error" and check for failure
>
> John
> ………………………………………………………………………………..
>
> John P. Nolan
> Math/Stat Dept., American University
> Gray Hall, 4400 Massachusetts Ave, NW
> Washington, DC 20016-8050
> Phone: 202-885-3140
> E-mail:  [hidden email]
> Web:   http://fs2.american.edu/jpnolan/www/
>
>
>
> -----Original Message----
> From: R-devel [mailto:[hidden email]] On Behalf Of Dan Tenenbaum
> Sent: Thursday, December 8, 2016 2:43 PM
> To: R-devel <[hidden email]>
> Subject: [Rd] require(..., quietly=TRUE) does not suppress warning
>
> Hi,
>
> The `quietly` argument of `require` is documented as follows:
>
> quietly: a logical.  If ‘TRUE’, no message confirming package
>          attaching is printed, and most often, no errors/warnings are
>          printed if package attaching fails.
>
> However:
>
>> require(foo, quietly=TRUE)
> Warning message:
> In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return =
> TRUE,  :
>  there is no package called ‘foo’
>
> Am I misreading the docs or is R misbehaving?
>
>> sessionInfo()
> R version 3.3.2 (2016-10-31)
> Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS Sierra 10.12.1
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> Dan
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: require(..., quietly=TRUE) does not suppress warning

Kevin Ushey
IMHO the strongest argument for suppressing the warning message here is the
fact that

    requireNamespace("foo", quietly = TRUE)

does not emit any warning message when the package 'foo' does not exist.

On Thu, Dec 8, 2016 at 12:51 PM, Dan Tenenbaum <[hidden email]>
wrote:

> Well, I'm getting a warning (not an error) when the package doesn't exist.
> I interpreted "most often" to mean that suppressing warnings/errors is why
> you'd most often use this argument, as most packages don't emit startup
> messages.
>
> And technically there isn't a problem with attaching the package, since we
> don't even try to attach packages that don't exist.
>
> So yes, very careful parsing of the docs suggests that the behavior is
> correct, but it does seem to violate the 'spirit' of what a user might
> expect. I am pretty sure I have used the 'if (!require("pkg"))
> install.packages("pkg")' pattern before without seeing this warning, so I
> wondered if the behavior had changed, and that's what prompted me to write.
>
> I know I can squelch the warning by wrapping the require() in
> suppressWarnings().
>
> Dan
>
>
> ----- Original Message -----
> > From: "John P. Nolan" <[hidden email]>
> > To: "Dan Tenenbaum" <[hidden email]>, "R-devel" <
> [hidden email]>
> > Sent: Thursday, December 8, 2016 12:37:02 PM
> > Subject: RE: require(..., quietly=TRUE) does not suppress warning
>
> > Well, it says "most often" no errors/warnings are given, so it is not
> > contradicting the docs!   It looks like the person/team that coded
> require( )
> > decided you should get an error when the package doesn't exist.
> >
> > If you want a silent loading, consider
> >     aaa <- try( library(foo,verbose=FALSE,quietly=TRUE),silent=TRUE)
> > and then check to see if aaa is of class "try-error" and check for
> failure
> >
> > John
> > ………………………………………………………………………………..
> >
> > John P. Nolan
> > Math/Stat Dept., American University
> > Gray Hall, 4400 Massachusetts Ave, NW
> > Washington, DC 20016-8050
> > Phone: 202-885-3140
> > E-mail:  [hidden email]
> > Web:   http://fs2.american.edu/jpnolan/www/
> >
> >
> >
> > -----Original Message----
> > From: R-devel [mailto:[hidden email]] On Behalf Of Dan
> Tenenbaum
> > Sent: Thursday, December 8, 2016 2:43 PM
> > To: R-devel <[hidden email]>
> > Subject: [Rd] require(..., quietly=TRUE) does not suppress warning
> >
> > Hi,
> >
> > The `quietly` argument of `require` is documented as follows:
> >
> > quietly: a logical.  If ‘TRUE’, no message confirming package
> >          attaching is printed, and most often, no errors/warnings are
> >          printed if package attaching fails.
> >
> > However:
> >
> >> require(foo, quietly=TRUE)
> > Warning message:
> > In library(package, lib.loc = lib.loc, character.only = TRUE,
> logical.return =
> > TRUE,  :
> >  there is no package called ‘foo’
> >
> > Am I misreading the docs or is R misbehaving?
> >
> >> sessionInfo()
> > R version 3.3.2 (2016-10-31)
> > Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS Sierra
> 10.12.1
> >
> > locale:
> > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> >
> > attached base packages:
> > [1] stats     graphics  grDevices utils     datasets  methods   base
> >
> > Dan
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel