How to Suppress R Startup Message

R suppress startupMessages from dependency

If you work with namespaces, you can specify the package in Imports, and load the necessary functions using import or importFrom. This way, the package is not attached, but the necessary functions can be loaded and used by your package. Without attaching, the startup messages are not given, so this approach assures you won't see any startup messages of packages specified in Imports.

Make sure you check that you imported everything that is of importance. If the package you import is dependent on other packages, I'm not sure everything you need to use those functions is imported. You might have to do a bit of puzzling to get everything you need loaded. On the plus side, using Imports assures that any dependencies check will be carried out correctly.

Another option is to not specify the package in Depends, but in Suggests in the DESCRIPTION file, and use the option @Dirk gave you. This will give a correct dependency check if 'dependencies=TRUE' is set in install.packages(). But personally I think using the namespaces is a lot more clean.

How to suppress R startup message?

Invoking R from the command line:

--quiet
--silent
-q

Do not print out the initial copyright and welcome messages.

--slave

Make R run as quietly as possible. This option is intended to support programs
which use R to compute results for them. It implies --quiet and --no-save.

How to remove R's startup messages in console mode?

You need to run whichever executable you're using with the --quiet command line option (--silent or -q will also work). The exact details of how to accomplish that will depend on how you typically launch R.

From the command line of a machine with R on its path, just do:

R --quiet

Or if (for example) you want to set up a clickable icon for the Windows GUI that launches without the "greeting", you can:

  1. Create a shortcut to the Rgui executable (stored in a path like $R_DIRECTORY/bin/i386/Rgui.exe).
  2. Right-click on the shortcut and then select 'Properties'.
  3. On the Shortcut tab, modify the 'Target' field to (the equivalent on your machine of) C:\R\R-current\bin\i386\Rgui.exe --quiet.
  4. Modify the 'Start in' field as desired.

R: Suppressing renv project startup message

You are correct that there isn't a specific documented way to configure this in renv. For now, you can set:

options(renv.verbose = FALSE)

before renv is loaded. (You may want to turn it back to TRUE if you want renv to display other messages as part of its normal work.)

How can I modify the startup message in R? Where is the code with this message?

You could set a personal startup message for R (which also will show in RStudio) by adding a line with message() in the .Rprofile.

In my case, the .Rprofile is in "My Documents" under Windows and is edited with the free tool Notepad++.

At the end of the file I have a line

### KoenV: Illustrate setting R startup message
message("I have changed my message")

The following appears when I start R

Sample Image

You can read more about accessing and editing this file in this post.

Disable messages upon loading a package

Just use suppressMessages() around your library() call:

edd@max:~$ R

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)
[...]

R> suppressMessages(library(ROCR))
R> # silently loaded
R> search()
[1] ".GlobalEnv" "package:ROCR" # it's really there
[3] "package:gplots" "package:KernSmooth"
[5] "package:grid" "package:caTools"
[7] "package:bitops" "package:gdata"
[9] "package:gtools" "package:stats"
[11] "package:graphics" "package:grDevices"
[13] "package:utils" "package:datasets"
[15] "package:methods" "Autoloads"
[17] "package:base"
R>

R package development how to suppress messages generated from dependency package?

Here are some things you can do to reduce the noise when loading packages with devtools::load_all:

  • devtools::load_all(..., quiet = TRUE) handles messages for this single package, but not necessarily dependent packages
  • try explicitly loading required packages in ./R/zzz.R in the onLoad function. For example:

    .onLoad <- function(libname, pkgname) {
    invisible(suppressPackageStartupMessages(
    sapply(c("tibble", "purrr", "dplyr", "tidyr", "ggplot2", "data.table"),
    requireNamespace, quietly = TRUE)
    ))
    }

    (BTW: I used sapply here for laziness, not that it adds much to things. It could easily have been a for loop with no consequence.)

    For a discussion about the use of requireNamespace in place of library, see "library vs require", and "Writing R Extensions" where it states

    R code in the package should call library or require only exceptionally. Such calls are never needed for packages listed in ‘Depends’ as they will already be on the search path. It used to be common practice to use require calls for packages listed in ‘Suggests’ in functions which used their functionality, but nowadays it is better to access such functionality via :: calls.

    What we are doing is technically not required, but I think by forcing doing it this way, it is encouraging more-silent operation. (This rides on the coat-tails of

    Notice that I used suppressPackageStartupMessages. "Courteous" package maintainers use packageStartupMessage instead of message for their loading messages: the latter takes a bit more work and is much less discriminant than the former, which is very easily suppressed without unintended consequences. There are many packages that do not do this, for which I think it's fair to submit a PR to fix.

    Another comment about requireNamespace: this means that the functions in those packages will not be in the search path of the R sessions. If the user will always be using certain packages (e.g., data.table or dplyr), then you might want to explicitly load them with library. From "Writing R Extensions" again:

    Field ‘Depends’ should nowadays be used rarely, only for packages which are intended to be put on the search path to make their facilities available to the end user (and not to the package itself): for example it makes sense that a user of package latticeExtra would want the functions of package lattice made available.

    However, if you're being good about your package, then you are using :: notation for all non-base packages anyway. There are certainly ways you can get around using ::, but (1) CRAN checks are rather intense at times, (2) explicit is usually "A Good Thing (tm)", and (3) it can actually make maintainability much easier (such as when a dependent package changes their API/ABI and you need to check all calls to their package, where searching for pkgname:: is much easier than searching for each of their functions individually).

  • Some packages use .onLoad too liberally, doing things that are not strictly necessary and/or have unneeded side-effect. For this, you can always write a function such as load_deppkgs_silently(updatesearchpath=TRUE) that can be called manually or on-load with the presence of an option. (I'm thinking about your end users here, I'm a big fan of providing flexibility and the ability to not load things they way I do.)



Related Topics



Leave a reply



Submit