R 抑制来自依赖项的启动消息 [英] R suppress startupMessages from dependency

查看:41
本文介绍了R 抑制来自依赖项的启动消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 R 包的一个依赖项在加载时显示启动消息.我想隐藏这些启动消息.

One of my R package's dependencies displays startup messages when loaded. I would like to suppress these startup messages.

到目前为止我发现的唯一修复是从我的描述文件中的 Depends: 行中删除有问题的包.然后在我的包的 .onLoad 中调用 suppressPackageStartupMessages(require("offendingPackage")).

The only fix I found so far was removing the offending package from the Depends: line in my DESCRIPTION file. Then calling suppressPackageStartupMessages(require("offendingPackage")) in .onLoad of my package.

我宁愿将有问题的包保留为我的 Depends 的一部分,但似乎 Depends 中指定的任何内容都会自动加载,因此无法抑制.

I would rather keep the offending package as part of my Depends, but it seems that anything specified in depends is automatically loaded and therefore can't be supressed.

推荐答案

如果你使用命名空间,你可以在 Imports 中指定包,并使用 importimportFrom.这样,包不会被附加,但必要的功能可以被你的包加载和使用.如果不附加,则不会给出启动消息,因此这种方法可确保您不会看到 Imports 中指定的包的任何启动消息.

If you work with namespaces, you can specify the package in Imports, and load the necessary functions using import or importFrom. This way, the package is not attached, but the necessary functions can be loaded and used by your package. Without attaching, the startup messages are not given, so this approach assures you won't see any startup messages of packages specified in Imports.

确保检查是否导入了所有重要的内容.如果您导入的包依赖于其他包,我不确定您使用这些功能所需的一切都已导入.您可能需要做一些令人费解的事情才能加载您需要的所有内容.从好的方面来说,使用 Imports 可确保正确执行任何依赖项检查.

Make sure you check that you imported everything that is of importance. If the package you import is dependent on other packages, I'm not sure everything you need to use those functions is imported. You might have to do a bit of puzzling to get everything you need loaded. On the plus side, using Imports assures that any dependencies check will be carried out correctly.

另一个选项是不在Depends 中指定包,而是在DESCRIPTION 文件中的Suggests 中指定包,并使用@Dirk 给您的选项.如果 install.packages() 中设置了dependencies=TRUE",这将提供正确的依赖项检查.但我个人认为使用命名空间要干净得多.

Another option is to not specify the package in Depends, but in Suggests in the DESCRIPTION file, and use the option @Dirk gave you. This will give a correct dependency check if 'dependencies=TRUE' is set in install.packages(). But personally I think using the namespaces is a lot more clean.

这篇关于R 抑制来自依赖项的启动消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆