[R] how to remove all messages when loading a library ?

jim holtman jholtman at gmail.com
Sun Sep 25 22:42:57 CEST 2016


Try enclosing the whole thing in "suppressMessages";

suppressMessages({
    if (!require("plyr",quietly=TRUE,warn.conflicts=FALSE))
suppressMessages(install.packages("plyr",quietly=TRUE))
    if (!require("dplyr",quietly=TRUE))
suppressMessages(install.packages("dplyr",quietly=TRUE))
    if (!require("stringr",quietly=TRUE))
suppressMessages(install.packages("stringr",quietly=TRUE))
    if (!require("readr",quietly=TRUE))
suppressMessages(install.packages("readr",quietly=TRUE))
    if (!require("tidyr",quietly=TRUE))
suppressMessages(install.packages("tidyr",quietly=TRUE))
    if (!require("XML",quietly=TRUE))
suppressMessages(install.packages("XML",quietly=TRUE))
    if (!require("Rcpp",quietly=TRUE))
suppressMessages(install.packages("Rcpp",quietly=TRUE))
    if (!require("rbenchmark",quietly=TRUE))
suppressMessages(install.packages("rbenchmark",quietly=TRUE))
    if (!require("tiff",quietly=TRUE))
suppressMessages(install.packages("tiff",quietly=TRUE))
    if (!require("xlsx",quietly=TRUE))
suppressMessages(install.packages("xlsx",quietly=TRUE))
    if (!require("ROracle",quietly=TRUE))
suppressMessages(install.packages("T:/CH/R/ROracle_1.2-2.zip", repos =
NULL, type = "source",quietly=TRUE))
})




Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Sun, Sep 25, 2016 at 3:22 PM, Fabien Tarrade <fabien.tarrade at gmail.com>
wrote:

> Hi there,
>
> I would like to remove all messages when I load library (I fact I am using
> "require" and "install.packages"). I tried many options and look at the
> documentation for the 2 functions.
> For example I am using the following piece of code: init.R
>
> print("step 1")
> # Install library if not installed
> if (!require("plyr",quietly=TRUE,warn.conflicts=FALSE))
> suppressMessages(install.packages("plyr",quietly=TRUE))
> if (!require("dplyr",quietly=TRUE)) suppressMessages(install.packa
> ges("dplyr",quietly=TRUE))
> if (!require("stringr",quietly=TRUE)) suppressMessages(install.packa
> ges("stringr",quietly=TRUE))
> if (!require("readr",quietly=TRUE)) suppressMessages(install.packa
> ges("readr",quietly=TRUE))
> if (!require("tidyr",quietly=TRUE)) suppressMessages(install.packa
> ges("tidyr",quietly=TRUE))
> if (!require("XML",quietly=TRUE)) suppressMessages(install.packa
> ges("XML",quietly=TRUE))
> if (!require("Rcpp",quietly=TRUE)) suppressMessages(install.packa
> ges("Rcpp",quietly=TRUE))
> if (!require("rbenchmark",quietly=TRUE)) suppressMessages(install.packa
> ges("rbenchmark",quietly=TRUE))
> if (!require("tiff",quietly=TRUE)) suppressMessages(install.packa
> ges("tiff",quietly=TRUE))
> if (!require("xlsx",quietly=TRUE)) suppressMessages(install.packa
> ges("xlsx",quietly=TRUE))
> if (!require("ROracle",quietly=TRUE)) suppressMessages(install.packa
> ges("T:/CH/R/ROracle_1.2-2.zip", repos = NULL, type =
> "source",quietly=TRUE))
> print("step 2")
>
> and I run the code in this way:
> > source("./init.R",encoding = "UTF-8",verbose=FALSE,echo=FAL
> SE,print.eval=FALSE)
>
> and I get the following output that I don't manage to remove:
>
> [1] "step 1"
>
> Attache Paket: ‘dplyr’
>
> Die folgenden Objekte sind maskiert von ‘package:plyr’:
>
>     arrange, count, desc, failwith, id, mutate, rename, summarise,
> summarize
>
> Die folgenden Objekte sind maskiert von ‘package:stats’:
>
>     filter, lag
>
> Die folgenden Objekte sind maskiert von ‘package:base’:
>
>     intersect, setdiff, setequal, union
> [1] "step 2"
>
> What is the way to get no messages at all when loading library ? ( or
> using other R function in general).
> I am trying to keep only the important messages and so far I am getting
> way too much messages.
>
> Thanks
> Cheers
> Fabien
>
>
> --
> Dr Fabien Tarrade
>
> Quantitative Analyst/Developer - Data Scientist
>
> Senior data analyst specialised in the modelling, processing and
> statistical treatment of data.
> PhD in Physics, 10 years of experience as researcher at the forefront of
> international scientific research.
> Fascinated by finance and data modelling.
>
> Zurich, Switzerland
>
> Email : contact at fabien-tarrade.eu <mailto:contact at fabien-tarrade.eu>
> Phone : www.fabien-tarrade.eu <http://www.fabien-tarrade.eu>
>
> LinkedIn <http://ch.linkedin.com/in/fabientarrade/> Twitter <
> https://twitter.com/fabtar> Google <https://plus.google.com/+Fabi
> enTarradeProfile/posts> Facebook <https://www.facebook.com/fabi
> en.tarrade.eu> Google <skype:fabtarhiggs?call> Xing <
> https://www.xing.com/profile/Fabien_Tarrade>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list