I am working on creating a package for the first time with roxygen2 and so far the project is coming along way. However, I noticed that I cannot seem to get the same layer of warning outputs in my console as with the devtools::test()
package.
To quickly recreate my issue:
- create a new package folder with the RStudio preset
- update the package to use roxygen2 documentation
- Change Hello.R to
#' Example dplyr Warning Function
#'
#' @import dplyr
#' @export
warn_repex <- function() {
testx <- data.frame("A" = c(1,1,2),"B" = c("X","X","Y"))
testy <- data.frame("A" = c(1,2), "C" = c("A","B"))
dplyr::left_join(testy,testx)
}
- Run once
usethis::use_test("ExampleRunthrough")
- Change the content of the test-ExampleRunthrough.R to
test_that("multiplication works", {
expect_type(warn_repex(), "list")
})
Now when we run the contents of the example package as user line by line we will get a warning along with the output:
> testx <- data.frame("A" = c(1,1,2),"B" = c("X","X","Y"))
> testy <- data.frame("A" = c(1,2), "C" = c("A","B"))
> dplyr::left_join(testy,testx)
Joining with `by = join_by(A)`
Warning in dplyr::left_join(testy, testx) :
Each row in `x` is expected to match at most 1 row in `y`.
ℹ Row 1 of `x` matches multiple rows.
ℹ If multiple matches are expected, set `multiple = "all"` to silence this warning.
A C B
1 1 A X
2 1 A X
3 2 B Y
However, if we install the package, or use devtools::load_all() and call the package function, we will only get the message regarding by which variable the columns are joined.
> devtools::load_all()
ℹ Loading testingBiocCode
> warn_repex()
Joining with `by = join_by(A)`
A C B
1 1 A X
2 1 A X
3 2 B Y
Now to the problem: I have the log of a partial traceback using the devtools::test()
function:
> devtools::test()
ℹ Testing testingBiocCode
✔ | F W S OK | Context
⠏ | 0 | ExampleRunthrough Joining with `by = join_by(A)`
✔ | 1 1 | ExampleRunthrough
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Warning (test-ExampleRunthrough.R:2): multiplication works
Each row in `x` is expected to match at most 1 row in `y`.
i Row 1 of `x` matches multiple rows.
i If multiple matches are expected, set `multiple = "all"` to silence this warning.
Backtrace:
1. testthat::expect_type(warn_repex(), "list")
at test-ExampleRunthrough.R:2:2
20. dplyr (local) `<fn>`(`<vctrs___>`)
21. dplyr:::rethrow_warning_join_matches_multiple(cnd, error_call)
22. dplyr:::warn_join(...)
23. dplyr:::warn_dplyr(...)
However, even with this three line code it is 'impossible' to properly narrow down the line which caused the warning eventually given these 23 stack of calls.
Thus, I obviously went on the adventure to be searching for the command, possibly combination, to recursively print warnings, eg. about deprecation, from all packages used in your package function as from a users/developers perspective as it is the case 'during' devtools::test()
.
In my case I have a code across several documents across several functions all interlinking to one large wrapper, and the cropped warning traceback that I see during devtools::test()
seems perfect, if I only knew how to see all steps of the stack; in the reproducible example posted here after stack call 1. display skips to 20., making the (to me) most important calls 2.-19. (where, as we know here, the error occurs) invisible to me.
I've tried various traceback functions and increasing the warn option etc without success, neither finding any good leads to how I can better look this issue up than by posting it in my own words. I hope it is unique and still interesting, if I missed something (which I most definitely must've) please let me know!
Thanks for taking your time in advance!