return overall percentage of coverage from covr::codecov

I used,

cov <- covr::package_coverage()
pct <- percent_coverage(cov)

However, this did not match codecov. I got 56.7 on travis but codecov shows 46.16. Am I using the wrong API? Hm, looks like percent_coverage does not include C++ files? I also tried by='line' but it didn't help,

pct <- percent_coverage(c1, by="line")

How to get the same number as shown on codecov?

1 Like

@jpritikin That is strange that the estimates are so different. I'm not sure exactly what could be causing that.

Based on the arguments to tally_coverage(), which is called by percent_coverage(), I think the default behavior is by "line".

args(covr::tally_coverage)
## function (x, by = c("line", "expression")) 
## NULL

What do you get when you set by = "expression"?

For my package, I get very similar estimates for line and expression, but the Codecov estimate of 83.74% is closer to the default line coverage reported by covr when run on my local machine.

library(covr)
cov <- package_coverage()
percent_coverage(cov)
## [1] 83.77545
percent_coverage(cov, by = "line")
## [1] 83.77545
percent_coverage(cov, by = "expression")
## [1] 83.84679

Also, a general note on forums: it is best practice to link to any other forums where you previously asked the question. The first thing I did after reading your question was to go to the GitHub Issues for covr, where I found your question and Jim's response:

codecov is reporting coverage per line, covr is reporting coverage per expression. See ?tally_coverage .

@jimhester Based on tally_coverage(), it appears that covr also reports line coverage by default. Could you please elaborate on your explanation? Thanks!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.