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