在R包NAMESPACE中抑制包加载消息

And*_*ndy 8 namespaces r

我正在导入一个名为"KernSmooth"的软件包,并希望启动消息不显示...

在我的描述文件中:

Package: test
Title: Test
Author: Mike
Description: Test
Maintainer: Mike
Depends: R(>= 2.10.0)
Imports: KernSmooth
Run Code Online (Sandbox Code Playgroud)

和我的命名空间文件:

import(KernSmooth)
Run Code Online (Sandbox Code Playgroud)

但是当我加载包时,我仍然得到启动消息:

KernSmooth 2.23 loaded
Copyright M. P. Wand 1997-2009
Run Code Online (Sandbox Code Playgroud)

我唯一的选择是不要在NAMESPACE中导入它并使用它

suppressMessages(require(KernSmooth)) 
Run Code Online (Sandbox Code Playgroud)

在我的R函数内避免消息?

Eug*_*gen 1

您可以在 R 项目的主目录中创建一个 .Rprofile 文件,您可以在其中告诉抑制消息以响应某些命令。下面是 .Rprofile 的示例,该示例抑制包(KernSmooth)的启动消息:

#This is the command you must put in your .Rprofile:
#obviously you can choose other packages instead of
#KernSmooth, as well as include other personal settings

suppressPackageStartupMessages(library(KernSmooth))
Run Code Online (Sandbox Code Playgroud)

现在,每次启动 R 会话时,加载包 KernSmooth 时都不会看到启动消息。

您可以在 R 控制台上键入“?Startup”来找到有关 .Rprofile 的更多信息,或者您可以查看此讨论中的 .Rprofile 示例:专家 R 用户,您的 .Rprofile 中有什么?