obrl-soil / h3jsr

Access Uber's h3-js library via R and V8 - https://uber.github.io/h3/#/documentation/overview/use-cases
https://obrl-soil.github.io/h3jsr/
Other
67 stars 5 forks source link

`test-custom_functions.R` errors if sf adds attributes to sf objects #10

Closed mikemahoney218 closed 8 months ago

mikemahoney218 commented 9 months ago

Hi there!

As currently written, test-custom_functions.R is partially testing that the underlying sf object never changes. Specifically, the expect_identical() here (second to last) will throw errors if sf ever changes the attributes attached to sf objects:

https://github.com/obrl-soil/h3jsr/blob/9ee5b62773cd2941aa47c0281380082bd61d1894/tests/testthat/test_custom_functions.R#L35-L54

The issue is that by using expect_identical(), testthat is partially testing if your objects contain exactly the same attributes. Because you're comparing against old saved sf objects, that means you're partially testing internal implementation details of the sf object that aren't guaranteed to remain the same over time. There's a bit more about how testing the attributes of objects created by other packages can be a problem on the Tidyverse blog.

At the moment, we're trying to add a new attribute to sf objects, which causes these tests to error. I'm writing to ask if you'd consider changing these tests to allow sf to improve the internal structure of sf objects.

I believe this test is looking to confirm that the ID and paths of these two objects are equal to each other. Would it be possible to change this test to expect_equal() with the check.attributes argument set to FALSE?

expect_equal(ins, paths_df, check.attributes = FALSE)

This change would mean this package is no longer blocking sf from making changes to the internal structure of sf objects, and would fix the immediate issue with the new attribute.

If you're open to it, I'd be happy to send you a PR to make these changes!

obrl-soil commented 9 months ago

Hi - yep happy to look over a PR for this - just can't get to it until this weekend.

mikemahoney218 commented 8 months ago

Thanks!