创建R软件包时,如何包括安装时显示的警告?有一个方便的roxygen2标签吗?

问题描述 投票:0回答:1

我会定期整理公司使用的某些功能。我想在软件包中包含警告,这些警告在安装/更新时显示,以通知同事可能对其代码产生下游影响的更改?我可以在包装文件中使用roxgen2标签吗?

r r-package roxygen2 deprecation-warning
1个回答
0
投票

据我所知,package:roxygen2没有这样的标签。

但是您可以直接编辑功能。这是RPushBullet的功能(在解析配置文件的上下文中)。

.onLoad <- function(libname, pkgname) {
    dotfile <- .getDotfile()                                    
    if (file.exists(dotfile)) .parseResourceFile(dotfile)       
}

.onAttach <- function(libname, pkgname) {
    packageStartupMessage("Attaching RPushbullet version ",
                          packageDescription("RPushbullet")$Version, ".")
    dotfile <- .getDotfile()
    if (file.exists(dotfile)) {
        packageStartupMessage("Reading ", dotfile)
        .parseResourceFile(dotfile)
    } else {
        txt <- paste("No file", dotfile, "found. Consider placing the",
                     "Pushbullet API key and your device id(s) there.")
        txt <- paste(strwrap(txt), collapse="\n")
        packageStartupMessage(txt)
        .pkgenv[["pb"]] <- NULL                     
    }
}

因此.onLoad()实际上不被允许打印消息,但是.onAttach()。由于以也可以抑制的方式显示它们比较礼貌,因此您不应直接使用cat()warning(),而应使用packageStartupMessage()

这些通常放置在文件R/init.RR/zzz.R中。

© www.soinside.com 2019 - 2024. All rights reserved.