我必须通过 github 安装一个包 - ggpatternremotes::install_github("coolbutuseless/ggpattern"
对于我通过 CRAN 安装/加载的所有其他包,我使用 and 抑制任何和所有消息suppressWarnings()
,suppressMessages()
但这些不适用于 install_github。
当我在这个线程之后将遥控器包装到 capture.output() 中时:R - suppressMessages / suppressWarnings not working
invisible(capture.output(remotes::install_github("coolbutuseless/ggpattern")))
它抑制了部分输出(显示为灰色而不是红色),但仍显示来自整个实际安装过程的所有消息(红色消息)。
有什么办法也可以压制这些吗?
我的脚本是交互式的,并且将由对这些消息感到困惑的用户提供。
编辑:
我从这个链接尝试了两个 system2 版本,它们都给了我一个错误(除了非常慢;几乎认为它崩溃了 R)
require(remotes)
# store a copy of system2
assign("system2.default", base::system2, baseenv())
# create a quiet version of system2
assign("system2.quiet", function(...)system2.default(..., stdout = FALSE,
stderr = FALSE), baseenv())
# overwrite system2 with the quiet version
assignInNamespace("system2", system2.quiet, "base")
suppressMessages(install_github("coolbutuseless/ggpattern"))
# reset system2 to its original version
assignInNamespace("system2", system2.default, "base")
# store a copy of system2
assign("system2.default", base::system2, baseenv())
# create a quiet version of system2
assign("system2.quiet", function(...)system2.default(..., stdout = FALSE,
stderr = FALSE), baseenv())
# redefine system2 to use system2.quiet if called from "install_github"
assignInNamespace("system2",
function(...) {
cls <- sys.calls()
from_install_github <-
any(sapply(cls, "[[", 1) == as.name("install_github"))
if(from_install_github) {
system2.quiet(...)
} else {
system2.default(...)
}},
"base")
suppressMessages(remotes::install_github("coolbutuseless/ggpattern"))
我收到以下错误
Error: Failed to install 'ggpattern' from GitHub:
C stack usage 7970672 is too close to the limit