How to suppress warning messages when loading a library? - r

I'm trying to run a r script from the command line, but I get warning messages when packages are loaded:
C:\Temp>Rscript myscript.r param
Warning message:
package 'RODBC' was built under R version 3.0.1
Warning message:
package 'ggplot2' was built under R version 3.0.1
Warning message:
package 'reshape2' was built under R version 3.0.1
Warning message:
package 'lubridate' was built under R version 3.0.1
Warning message:
package 'scales' was built under R version 3.0.1
I' tried to use suppressPackageStartupMessages:
suppressPackageStartupMessages(library(RODBC))
or supressMessages
suppressMessages(library(RODBC))
but these did not suppress these messages. How to get rid of these warnings?

These are not messages but warnings. You can do:
suppressWarnings(library(RODBC))
or
suppressWarnings(suppressMessages(library(RODBC)))
to suppress both types.

I put this at the top of all my scripts and preface my library loads with it:
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
Then you can load the library thusly:
shhh(library(tidyverse))
and rely on perfect silence.

Related

Error: package or namespace load failed for ‘CGPfunctions’ [duplicate]

I am getting the following error when I am loading a few libraries in R:
library(forecast)
Error : object ‘f_eval’ is not exported by 'namespace:lazyeval'
In addition: Warning message:
package ‘forecast’ was built under R version 3.3.2
Error: package or namespace load failed for ‘forecast’
library(tsoutliers)
Error : object ‘f_eval’ is not exported by 'namespace:lazyeval'
In addition: Warning message:
package ‘tsoutliers’ was built under R version 3.3.2
Error: package or namespace load failed for ‘tsoutliers’
I have tried reinstalling the packages but it didn't help. Also, I was able to use the forecast package previously but I started facing this error post the installation of tsoutliers package.
How can I resolve this issue?
This should do the job for you:
install.packages('lazyeval')
In the future, try and provide a bit more about your system and install, using the output from:
sessionInfo()

Why do I get an error when running ggplot2 in R 3.5.0?

I am trying to run ggplot2 in R 3.5.0 but it is giving the following error. I can only use this version since it is the only approved at my company.
I have tried removing the package e reinstalling different version but only the ggplot2 version 3.2.0 successfully installed. I tried newer and older versions and it does not install. I am using a Windows computer.
library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in rbind(info, getNamespaceInfo(env, "S3methods")):
number of columns of matrices must match (see arg 2)
In addition: Warning message:
package ‘ggplot2’ was built under R version 3.5.3

Why do I get an error when I try to load ggplot2 in R?

When I run:
library("ggplot2")
I get the error below:
Error: package or namespace load failed for ‘ggplot2’:
object ‘enexprs’ is not exported by 'namespace:rlang'
In addition:
Warning message:
package ‘ggplot2’ was built under R version 3.4.4
Any idea how I can solve this issue?
Please install the latest version of rlang to solve this error.

Rcmndr plugin not running

I am trying to run this rcmndr plugin for my class and it's not working. I installed all the necessary packages and it appeared to install correctly but I am getting this package or namespace load failure. The GUI appears for a split second when I enter the library command, then disappears with the error. It seems to be an issue with the namespace and .onattach but I couldn't find any existing answers or resources for this issue.
https://cran.r-project.org/web/packages/RcmdrPlugin.BCA/index.html
> library(RcmdrPlugin.BCA)
Loading required package: Rcmdr
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: car
Loading required package: sandwich
Rcmdr Version 2.2-3
Loading required package: BCA
Warning: package 'BCA' was built under R version 3.2.3
Loading required package: flexclust
Warning: package 'flexclust' was built under R version 3.2.3
Loading required package: grid
Loading required package: lattice
Loading required package: modeltools
Loading required package: stats4
Error : .onAttach failed in attachNamespace() for 'RcmdrPlugin.BCA', details:
call: get(Menus[m, 5])
error: object 'importRODBCtable' not found
In addition: Warning messages:
1: package ‘RcmdrPlugin.BCA’ was built under R version 3.2.3
2: package ‘Rcmdr’ was built under R version 3.2.3
3: package ‘RcmdrMisc’ was built under R version 3.2.3
4: package ‘car’ was built under R version 3.2.3
Error: package or namespace load failed for 'RcmdrPlugin.BCA'
I got alternative to run this plugin in R commander.
Open R Commander by using:
library(Rcmdr)
R Commander dialogue box will appear.
In R Script load BCA library-
lapply(list('BCA', 'splines', 'RcmdrMisc', 'car', 'sandwich', 'flexclust', 'grid','lattice','modeltools','stats4','RODBC'), require, character.only = TRUE)
Click on Submit button.
If you don't have RODBC package (which is not there in my case), install it separately and then run above commands. To install use:
install.packages("RODBC")
And now you exactly have what you will get after loading RcmdrPlugin.BCA library.
I faced a similar situation. Having tried a bunch of things - none worked - I finally uninstalled R and deleted the remaining files from under the "Program Files" directory in Windows. I then reinstalled R and RcmdrPlugin.BCA and this time it worked.
You could also refer to this URL for help http://r.789695.n4.nabble.com/Unable-to-run-RcmdrPlugin-survival-using-3-2-2-with-Windows-10-td4711796.html

Error installing R package - Kernsmooth

I am getting error while installing package KernSmooth. How can I install this pacakge ?
Getting warning messages on not able to access index for repository and one with package not available. Below are example warning message-
Warning: unable to access index for repository
http://lib.stat.cmu.edu/R/CRAN/src/contrib Warning message: package
‘KernSmooth’ is not available (for R version 3.2.1)

Resources