Skip to content

R6 classes whose names start with a "." are treated as irrelevant for coverage #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jameslamb opened this issue Mar 27, 2019 · 0 comments

Comments

@jameslamb
Copy link
Contributor

I noticed today that R6 classes whose names start with a . (a valid name) are not treated as relevant for coverage by covr.

Minimum working example

All in the same directory

file.R

.function_a <- function(...){
    print("hello")
    print("how are you?")
    print("I've been wondering")
    return(invivsible(NULL))
}

ClassA <- R6::R6Class(
    "ClassA",
    public = list(
        initialize = function(x = 5){
            y <- x + 8
            z <- y + 5
            print(z)
        }
    )
)

.ClassB <- R6::R6Class(
    "ClassB",
    public = list(
        initialize = function(x = 5){
            y <- x + 8
            z <- y + 5
            print(z)
        }
    )
)

tests.R

source("file.R")

library(testthat)

test_that("ClassA test", {
    expect_true({
        ClassA$new()
        TRUE
    })
})

From within the same directory, run the tests and view coverage HTML:

x <- covr::file_coverage(
    source_files = "file.R"
    , test_files = "tests.R"
)

out_html <- covr::report(x, file = "thing.html")
utils::browseURL("thing.html")

As you can see in the output, functions starting with a . and constructors of R6 classes in CamelCase are considered relevant for coverage, but the constructor of an R6 class whose object name starts with a . is completely ignored:

image

session info ``` R version 3.5.1 (2018-07-02) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] testthat_2.0.1

loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 later_0.8.0 digest_0.6.18 withr_2.1.2 mime_0.6 R6_2.3.0
[7] jsonlite_1.6 xtable_1.8-3 covr_3.2.1 magrittr_1.5 rlang_0.3.1 lazyeval_0.2.1
[13] promises_1.0.1 rex_1.1.2 DT_0.5 tools_3.5.1 htmlwidgets_1.3 crosstalk_1.0.0
[19] shiny_1.2.0 httpuv_1.4.5.1 yaml_2.2.0 compiler_3.5.1 htmltools_0.3.6

</details>


I'm going to try to work on this and figure out why it's happening.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant