4

I've googled around and I saw that if I use suppressPackageStartupMessages() I should be able to fix my issue, but turns out, nothing happened.

I'm loading my packages like this:

if (!require("gplots", quietly = T)) {
    sink("/dev/null")
    suppressPackageStartupMessages(suppressWarnings(suppressMessages(install.packages("gplots"))))
    suppressPackageStartupMessages(suppressWarnings(suppressMessages(library("gplots", quietly = T))))
}

and while my script is running I get these messages:

Attaching package: ‘gplots’

The following object is masked from ‘package:IRanges’:

    space

The following object is masked from ‘package:S4Vectors’:

    space

The following object is masked from ‘package:stats’:

    lowess

On another package,

if (!require("Rmixmod", quietly = T)){
    sink("/dev/null")
    suppressPackageStartupMessages(suppressWarnings(suppressMessages(install.packages("R_packages/Rmixmod_2.0.1.tar.gz", type="source"))))
}

I'm also getting the citation options while loading, and i'm also trying to silence that as well.

Rmixmod version 2.0.1 loaded
R package of mixmodLib version 3.0.1

Condition of use
----------------
Copyright (C)  MIXMOD Team - 2001-2013

MIXMOD is publicly available under the GPL license (see www.gnu.org/copyleft/gpl.html)
You can redistribute it and/or modify it under the terms of the GPL-3 license.
Please understand that there may still be bugs and errors. Use it at your own risk.
We take no responsibility for any errors or omissions in this package or for any misfortune that may befall you or others as a result of its use.

Please report bugs at: http://www.mixmod.org/article.php3?id_article=23

More information on : www.mixmod.org

Package 'mclust' version 5.2.1
Type 'citation("mclust")' for citing this R package in publications.

How can this be done?

Jack
  • 722
  • 3
  • 8
  • 24

1 Answers1

5

Not sure if anyone is still looking for an answer to this one but

suppressWarnings(suppressMessages(library("dplyr")))

works perfectly on Jupyter Notebooks. I typically define a function like this:

import_library = function(lib_name){
    suppressWarnings(suppressMessages(require(lib_name, character.only = TRUE)))
}
import_library('dplyr')

Note that, inside the user-defined function, library(...) will not work, so use require(...). The character.only = TRUE is also necessary to circumvent R from trying to load lib_name as name of library, rather than actual library (in our case dplyr).

A similar answer can be found here.

ImranAli
  • 166
  • 1
  • 8