删除R中的加载包消息
我在R脚本中使用以下软件包:删除R中的加载包消息,r,console,package,loading,R,Console,Package,Loading,我在R脚本中使用以下软件包: library(uba) library(performanceEstimation) library(UBL) library(DMwR) 这些包始终发出消息:“正在加载包xyz”。如果我没有像下面那样抑制“加载包”消息: 我在控制台中收到以下消息: 有没有其他方法可以抑制消息?我可能会在许多其他R脚本中使用这些包,但我不想每次都这样做。一种方法是编写一个简单的函数,它接收包向量并以您想要的方式抑制输出,如下例所示 library_suppress <-
library(uba)
library(performanceEstimation)
library(UBL)
library(DMwR)
这些包始终发出消息:“正在加载包xyz”。如果我没有像下面那样抑制“加载包”消息:
我在控制台中收到以下消息:
有没有其他方法可以抑制消息?我可能会在许多其他R脚本中使用这些包,但我不想每次都这样做。一种方法是编写一个简单的函数,它接收包向量并以您想要的方式抑制输出,如下例所示
library_suppress <- function(packages, character.only = TRUE, ...){
for(i in seq_along(packages))
suppressPackageStartupMessages(
library(packages[i], character.only = character.only, ...)
)
}
packages <- c('operators', 'class', 'fields', 'spam', 'dotCall64', 'grid', 'MBA', 'gstat', 'automap', 'sp', 'randomForest')
library_suppress(packages)
注意:这不会抑制警告消息
Loading required package: operators
Attaching package: 'operators'
The following objects are masked from 'package:base':
options, strrep
Loading required package: class
Loading required package: fields
Loading required package: spam
Loading required package: dotCall64
Loading required package: grid
Spam version 2.5-1 (2019-12-12) is loaded.
Type 'help( Spam)' or 'demo( spam)' for a short introduction
and overview of this package.
Help for individual functions is also obtained by adding the
suffix '.spam' to the function name, e.g. 'help( chol.spam)'.
Attaching package: 'spam'
The following objects are masked from 'package:base':
backsolve, forwardsolve
Loading required package: maps
See https://github.com/NCAR/Fields for
an extensive vignette, other supplements and source code
Loading required package: ROCR
Loading required package: gplots
Attaching package: 'gplots'
The following object is masked from 'package:stats':
lowess
Loading required package: DMwR
Loading required package: lattice
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Attaching package: 'DMwR'
The following object is masked from 'package:fields':
unscale
Attaching package: 'uba'
The following object is masked from 'package:base':
subset
Loading required package: MBA
Loading required package: gstat
Loading required package: automap
Loading required package: sp
Loading required package: randomForest
randomForest 4.6-14
Type rfNews() to see new features/changes/bug fixes.
Attaching package: 'UBL'
The following objects are masked from 'package:uba':
phi, phi.control
library_suppress <- function(packages, character.only = TRUE, ...){
for(i in seq_along(packages))
suppressPackageStartupMessages(
library(packages[i], character.only = character.only, ...)
)
}
packages <- c('operators', 'class', 'fields', 'spam', 'dotCall64', 'grid', 'MBA', 'gstat', 'automap', 'sp', 'randomForest')
library_suppress(packages)