Re: [Rd] Silently loading and Depends: versus NAMESPACE imports

From: Suraj Gupta <surajg_at_gmail.com>
Date: Thu, 23 Feb 2012 00:40:52 -0500

Dirk - I'm having the same issue. Could you provide the details of your solution?

On Sat, Jan 28, 2012 at 11:15 AM, Dirk Eddelbuettel <edd_at_debian.org> wrote:

>
> On 28 January 2012 at 16:52, Uwe Ligges wrote:
> |
> |
> | On 27.01.2012 15:57, Dirk Eddelbuettel wrote:
> | >
> | > On 12 January 2012 at 12:12, Hervé Pagès wrote:
> | > | Hi Dirk,
> | > |
> | > | On 01/11/2012 11:42 AM, Dirk Eddelbuettel wrote:
> | > |>
> | > |> R CMD check really hates it when my .onLoad() function contains
> | > |> suppressMessages(library(foo))
> | > |
> | > | Note that you can always fool 'R CMD check' by doing something like:
> | > |
> | > | sillyname<- library
> | > | suppressMessages(sillyname("foo"))
> | > |
> | > | Also isn't suppressPackageStartupMessages() more appropriate?
> | > |
> | > |>
> | > |> However, _and for non-public packages not going to CRAN_ I prefer
> doing this
> | > |> over using explicit Depends or import statements in the NAMESPACE
> file as the
> | > |> latter do not give me an ability to make the loading less verbose.
> With the
> | > |> R universe of packages being as vast as at is, a simple
> (non-public) package
> | > |> I have loads about five or six other packages explicitly, each of
> which loads
> | > |> even more. The net result is totally intimidating _sixty lines
> full_ of
> | > |> verbose noise that is meaningful to me as an R programmer, but not
> for the
> | > |> colleagues expected to use the packages. It looks rather
> uninviting, frankly.
> | > |>
> | > |> How do I use imports via NAMESPACE, and yet keep the noise level
> down to zero?
> | > |
> | > | If you only need to import foo (i.e. and actually don't need to
> attach
> | > | it to the search path) then putting foo in Imports and using import
> | > | statements in NAMESPACE will keep the noise level down to zero.
> | >
> | > I don't think so.
> | >
> | > I have an internal package, call it fooUtils, that (among other
> things) needs
> | > to figure at startup whether it runs on this or that OS.
> | >
> | > So that package fooUtils does
> | >
> | > .onLoad<- function(libname, pkgname) {
> | >
> | > if (.Platform$OS.type == "windows") {
> | > packageStartupMessage("Running on Windows")
> | > # [... more stuff here ... ]
> | > } else if (.Platform$OS.type == "unix") {
> | > packageStartupMessage("Running on Linux")
> | > # [... more stuff here ... ]
> | > } else {
> | > warning("Platform ", .Platform$OS.type, " not recognised")
> | > drives<- NULL
> | > }
> | >
> | > # ....
> | >
> | > }
> |
> | Are you sure you want the messages in .onLoad rather than .onAttach?
>
> Thanks Uwe -- looks like that was exactly the hint I needed.
>
> By splitting the task across onLoad and onAttach I seem to be able to get
> want I need even if the package is "tickled" via NAMESPACE's importFrom.
>
> Dirk
>
> | See ?.onLoad and its "Good practice" section:
> |
> | "Loading a namespace should where possible be silent, with startup
> | messages given by .onAttach. These messages (and any essential ones from
> | .onLoad) should use packageStartupMessage so they can be silenced where
> | they would be a distraction."
> |
> | Best,
> | Uwe
> |
> |
> |
> | >
> | > and contrary to your claim, this is not silent as soon as I do
> | >
> | >
> | > importFrom(fooUtils, someThing)
> | >
> | >
> | > the messages above pop up. While I can suppress them for 'normal'
> loads via
> | >
> | > suppressMessages(library(fooUtils))
> | >
> | > or
> | >
> | > suppressPackageStartupMessages(library(fooUtils))
> | >
> | >
> | > I cannot suppress them via NAMESPACE imports.
> | >
> | > Dirk
> | >
> | > | So I guess your question is: how do we suppress package startup
> messages
> | > | for packages listed in Depends?
> | > |
> | > | Cheers,
> | > | H.
> | > |
> | > |>
> | > |> Dirk
> | > |>
> | > |
> | > |
> | > | --
> | > | Hervé Pagès
> | > |
> | > | Program in Computational Biology
> | > | Division of Public Health Sciences
> | > | Fred Hutchinson Cancer Research Center
> | > | 1100 Fairview Ave. N, M1-B514
> | > | P.O. Box 19024
> | > | Seattle, WA 98109-1024
> | > |
> | > | E-mail: hpages_at_fhcrc.org
> | > | Phone: (206) 667-5791
> | > | Fax: (206) 667-1319
> | >
>
> --
> "Outside of a dog, a book is a man's best friend. Inside of a dog, it is
> too
> dark to read." -- Groucho Marx
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 23 Feb 2012 - 05:43:13 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 23 Feb 2012 - 18:20:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive