R包中打印函数的测试覆盖率

R包中打印函数的测试覆盖率,r,code-coverage,testthat,R,Code Coverage,Testthat,我在R软件包中有一个简单的打印功能: print.tabyl <- function(x){ print.data.frame(x, row.names = FALSE) } print.tabyl根据@alistaire的建议,我使用capture.output编写了一个测试: test_that("print.tabyl prints without row numbers", { expect_equal( mtcars %>% tabyl(am, cyl)

我在R软件包中有一个简单的打印功能:

print.tabyl <- function(x){
  print.data.frame(x, row.names = FALSE)
}

print.tabyl根据@alistaire的建议,我使用
capture.output
编写了一个测试:

test_that("print.tabyl prints without row numbers", {
  expect_equal(
    mtcars %>% tabyl(am, cyl) %>% capture.output(),
    c(" am 4 6  8", "  0 3 4 12", "  1 8 3  2")
  )
})
这捕获到
行。缺少名称
;此结果不同于仍有行号的
capture.output(print.data.frame(mtcars%>%tabyl(am,cyl))


使用
capture.output
测试函数并计算codecov.io跟踪的覆盖率。

您是否在
testthat
包中看到函数
expect\u output()
?我在我的存储库中使用它来测试打印输出:
expect\u输出(print.tabyl(您的\u对象))
或将其包装在
capture.output
中,然后返回打印行的字符串