我想在生成使用多个包的答案/问题1时使用reprex
个包.假设我想提供以下答案
library("gdata")
dfA <- data.frame(colA = c(1, 2), colB = c(3, 4))
ls()
mv(from = "dfA", to = paste0("df", "B"))
ls()
如果我将此代码直接传递到reprex,输出将如下所示:
library("gdata")
#> gdata: read.xls support for 'XLS' (Excel 97-2004) files ENABLED.
#>
#> gdata: Unable to load perl libaries needed by read.xls()
#> gdata: to support 'XLSX' (Excel 2007+) files.
#>
#> gdata: Run the function 'installXLSXsupport()'
#> gdata: to automatically download and install the perl
#> gdata: libaries needed to support Excel XLS and XLSX formats.
#>
#> Attaching package: 'gdata'
#> The following object is masked from 'package:stats':
#>
#> nobs
#> The following object is masked from 'package:utils':
#>
#> object.size
#> The following object is masked from 'package:base':
#>
#> startsWith
dfA <- data.frame(colA = c(1, 2), colB = c(3, 4))
ls()
#> [1] "dfA"
mv(from = "dfA", to = paste0("df", "B"))
ls()
#> [1] "dfB"
由reprex package(v2.0.1)于2022-03-23创建
与包裹装载相关的不相关信息丢失.另一种方法是 suppress 包启动消息:
suppressPackageStartupMessages(library("gdata"))
dfA <- data.frame(colA = c(1, 2), colB = c(3, 4))
ls()
#> [1] "dfA"
mv(from = "dfA", to = paste0("df", "B"))
ls()
#> [1] "dfB"
由reprex package(v2.0.1)于2022-03-23创建
上述reprex输出通过以下方式生成:
library("reprex")
reprex(x = {
suppressPackageStartupMessages(library("gdata"))
dfA <- data.frame(colA = c(1, 2), colB = c(3, 4))
ls()
mv(from = "dfA", to = paste0("df", "B"))
ls()
}, venue = "so")
Question
有没有更干净的方法?Reprex提供tidyverse_quiet
个,但我想知道是否有一种聪明的方法可以"扩展"这个参数,使其适用于多个包?在一个加载多个包的假设答案中,我希望避免多次编写suppressPackageStartupMessages
来 suppress 不必要的输出.
从不同的包中调用多个函数时,编写package::function
可能会很繁重.
1For reference, I started thinking on that that after contributing 100 to 101.