首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除R中的加载包消息

删除R中的加载包消息
EN

Stack Overflow用户
提问于 2020-02-15 19:28:40
回答 1查看 184关注 0票数 0

我在我的R脚本中使用了以下包:

代码语言:javascript
复制
library(uba)
library(performanceEstimation)
library(UBL)
library(DMwR)

这些包总是发出消息:‘加载包xyz’。如果我不像下面所做的那样取消“加载包”消息:

代码语言:javascript
复制
suppressPackageStartupMessages(library(operators))
suppressPackageStartupMessages(library(class))
suppressPackageStartupMessages(library(fields))
suppressPackageStartupMessages(library(spam))
suppressPackageStartupMessages(library(dotCall64))
suppressPackageStartupMessages(library(grid))
suppressPackageStartupMessages(library(DMwR))
suppressPackageStartupMessages(library(uba))
suppressPackageStartupMessages(library(UBL))
suppressPackageStartupMessages(library(MBA))
suppressPackageStartupMessages(library(gstat))
suppressPackageStartupMessages(library(automap))
suppressPackageStartupMessages(library(sp))
suppressPackageStartupMessages(library(randomForest))

library(uba)  # util used below
library(performanceEstimation)
library(UBL)
library(DMwR)

我在我的控制台中得到以下消息

代码语言:javascript
复制
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

有其他方法来抑制消息吗?我可能会在许多其他R脚本中使用这些包,我不想每次都这么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-15 22:57:28

一种方法是编写一个简单的函数,它接受包的向量,并以您想要的方式抑制输出,如下所示。

代码语言:javascript
复制
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)

注意,这并不会抑制警告消息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60242367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档