- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to stop printing messages while loading a package in R?
There are some annoying messages we get while loading a package in R and they are not useful until and unless we are not loading a new package. Since these messages looks like outputs they might be confusing especially when we are analysing string data. Therefore, we must get rid of them.
An example of message while loading BSDA package:>
Loading required package − lattic
Attaching package − ‘BSDA’
The following object is masked from ‘package:datasets’ −
Here we have some messages while loading the package BSDA but we might not be interested in those messages if we are sure that package is installed in R and we are loading it correctly. Also, if a package is frequently used then these messages are annoying and we want to get rid of them. So, there is an easily solution to this, we can use suppressPackageStartupMessages while loading the package.
When we use suppressPackageStartupMessages function, it disables all the messages we get while loading a package if the package is installed in R but it will not make an impact on errors or warnings.
> suppressPackageStartupMessages(library(ROCR)) Error in library(ROCR) : there is no package called ‘ROCR’
Since I don’t have package ROCR installed in my R version, suppressPackageStartupMessages function throws an error.
> suppressPackageStartupMessages(library(data.table)) Warning message: package ‘data.table’ was built under R version 3.6.2
Now, I do have data.table package installed but it was built under version 3.6.2 so it is showing a warning message because the version of R I am using for this is 3.6.1.
Let’s have a look at one more example. Suppose we want to load gdata package that comes with a lot of messages as shown below −
> library(gdata) gdata: Unable to locate valid perl interpreter gdata: gdata: read.xls() will be unable to read Excel XLS and XLSX files gdata: unless the 'perl=' argument is used to specify the location of a gdata: valid perl intrpreter. gdata: gdata: (To avoid display of this message in the future, please ensure gdata: perl is installed and available on the executable search path.) gdata: Unable to load perl libaries needed by read.xls() gdata: to support 'XLX' (Excel 97-2004) files. gdata: Unable to load perl libaries needed by read.xls() gdata: to support 'XLSX' (Excel 2007+) files. gdata: Run the function 'installXLSXsupport()' gdata: to automatically download and install the perl gdata: libaries needed to support Excel XLS and XLSX formats. Attaching package: ‘gdata’
The following object is masked from ‘package:purrr’ −
The following objects are masked from ‘package:data.table’ −
The following object is masked from ‘package:stats’ −
The following object is masked from ‘package:utils’ −
The following object is masked from ‘package:base’ −
Now we can easily ignore these message as follows −
But if we have installed a new package then we must not ignore these messages because there might be some useful for us as we are new to that package.
- How to stop default printing of large numbers in R?
- How to stop a page loading from Selenium in chrome?
- Loading messages from Excel to SAP table T100
- How to Stop the page loading in firefox programmatically in Selenium ?
- How to detach a package in R?
- How to display progress while loading a url to webview in android?
- How to display progress bar while loading a url to webView in Android?
- How to increase the printing limit in R?
- Reduce decimals while printing in Arduino
- How to find the functions inside a package in R?
- Avoiding quotes while printing strings in Python
- How to add background color to headers or footers in an Excel sheet while printing
- Why do backslashes appear twice while printing in Python?
- How to find the name of the author of a package in R?
- How to extract columns of a data frame in R using dplyr package?