Skip to content
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

Some tests failing with devtools::check(), not with devtools::test() #1713

Closed
dimfalk opened this issue Nov 13, 2022 · 1 comment
Closed

Comments

@dimfalk
Copy link

dimfalk commented Nov 13, 2022

Hi everyone,

I'm really not sure whether this is the right place to ask or if this is an issue at all - since I'm currently working on tests for my very first package, I totally might have messed up somewhere unconsciously - but let me try to describe the problem first:

As already addressed in the topic, some of my tests are failing with devtools::check() at the moment. Having read some material on this topic, e.g. at community.rstudio.com and hadley/r-pkgs#483, I checked the mentioned usual suspects like dependencies in DESCRIPTION and namespace issues, but was not able to resolve this yet, unfortunately.

However, this is the repo I am currently working on.

Everything was fine via devtools::check() before a recent commit, where I relocated some of the function calls to be tested from setup.R to the relevant test_that() blocks because it felt like it was the wrong place to run the code (I did not want to repeat these calls at first) and then I picked up the recommendation to "inline everything inside test_that() calls" at r-pkgs.org.

All tests (7) located in test-calc_designstorm.R currently fail with basically the same error:

── Error ('test-calc_designstorm.R:3'): Output class is as expected. ───────────
<vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
Error in `vec_size()`: `x` must be a vector, not a <sfc_POLYGON/sfc> object.

Backtrace:
     ▆
  1. ├─kostra2010R::calc_designstorm(kostra_ref, d = 60, tn = 20, type = "EulerII") at test-calc_designstorm.R:3:2
  2. │ ├─dplyr::filter(tiles, INDEX_RC == attr(x, "id"))
  3. │ └─dplyr:::filter.data.frame(tiles, INDEX_RC == attr(x, "id"))
  4. │   ├─dplyr::dplyr_row_slice(.data, loc, preserve = .preserve)
  5. │   └─dplyr:::dplyr_row_slice.data.frame(.data, loc, preserve = .preserve)
  6. │     ├─dplyr::dplyr_reconstruct(vec_slice(data, i), data)
  7. │     │ └─dplyr:::dplyr_new_data_frame(data)
  8. │     │   ├─row.names %||% .row_names_info(x, type = 0L)
  9. │     │   └─base::.row_names_info(x, type = 0L)
 10. │     └─vctrs::vec_slice(data, i)
 11. └─vctrs:::stop_scalar_type(`<fn>`(`<s_POLYGO>`), "x", `<fn>`(vec_size()))
 12.   └─vctrs:::stop_vctrs(...)
 13.     └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))

What I assume to be the potential source for this error is this code block where I filter an sf obejct with dplyr by attributes. Probably the way I call the lazy loaded data in line 131 causes this to fail. However, no error messages pop up with other tests where I also access some of the other datasets. But maybe the way I load my "reference datasets" in setup.R is also not best-practice.

I was also able to find a "workaround" - restoring the state before mentioned commit - and found out that all tests mysteriously pass when I call get_stats() before, either in setup.R or in even in the first test_that() block (c.f. here). Comment this line again to reproduce failing tests.

I can't wrap my head around this since nothing relevant happens by calling get_stats() from the perspective of calc_designstorm(), at least from my naive point of view. Also, since I thought the individual containers are to be regarded as independent environments (?), why does a call in the first container influences all the others resulting in passing the test?

Thank you very much in advance!

@dimfalk
Copy link
Author

dimfalk commented Jan 31, 2023

Fixed by adding import(sf) to NAMESPACE - e.g. via @import sf roxygen tag.

@dimfalk dimfalk closed this as completed Jan 31, 2023
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