gpt4 book ai didi

r - 禁止包加载消息

转载 作者:行者123 更新时间:2023-12-02 04:25:37 26 4
gpt4 key购买 nike

我用谷歌搜索了一下,发现如果我使用suppressPackageStartupMessages()我应该能够解决我的问题,但事实证明,什么也没发生。

我正在像这样加载我的包:

if (!require("gplots", quietly = T)) {
sink("/dev/null")
suppressPackageStartupMessages(suppressWarnings(suppressMessages(install.packages("gplots"))))
suppressPackageStartupMessages(suppressWarnings(suppressMessages(library("gplots", quietly = T))))
}

当我的脚本运行时,我收到以下消息:

Attaching package: ‘gplots’

The following object is masked from ‘package:IRanges’:

space

The following object is masked from ‘package:S4Vectors’:

space

The following object is masked from ‘package:stats’:

lowess

在另一个包上,

if (!require("Rmixmod", quietly = T)){
sink("/dev/null")
suppressPackageStartupMessages(suppressWarnings(suppressMessages(install.packages("R_packages/Rmixmod_2.0.1.tar.gz", type="source"))))
}

我还在加载时获取引文选项,并且我也试图使其保持沉默。

Rmixmod version 2.0.1 loaded
R package of mixmodLib version 3.0.1

Condition of use
----------------
Copyright (C) MIXMOD Team - 2001-2013

MIXMOD is publicly available under the GPL license (see www.gnu.org/copyleft/gpl.html)
You can redistribute it and/or modify it under the terms of the GPL-3 license.
Please understand that there may still be bugs and errors. Use it at your own risk.
We take no responsibility for any errors or omissions in this package or for any misfortune that may befall you or others as a result of its use.

Please report bugs at: http://www.mixmod.org/article.php3?id_article=23

More information on : www.mixmod.org

Package 'mclust' version 5.2.1
Type 'citation("mclust")' for citing this R package in publications.

如何做到这一点?

最佳答案

不确定是否有人仍在寻找这个问题的答案,但是

suppressWarnings(suppressMessages(library("dplyr")))

在 Jupyter Notebooks 上完美工作。我通常定义这样的函数:

import_library = function(lib_name){
suppressWarnings(suppressMessages(require(lib_name, character.only = TRUE)))
}
import_library('dplyr')

请注意,在用户定义函数内部,library(...)不起作用,所以使用 require(...)character.only = TRUE还需要避免 R 尝试加载 lib_name作为库的名称,而不是实际的库(在我们的例子中 dplyr )。

可以找到类似的答案 here .

关于r - 禁止包加载消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42285053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com