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

Update slice_sample in dplyr_methods.R #72

Merged
merged 3 commits into from
Aug 31, 2023

Conversation

noriakis
Copy link
Contributor

Hello, this PR clears the warning in slice_sample. I would be grateful if you could review the code.
Related to: stemangiola/tidySingleCellExperiment#90

> data(pbmc_small)
> pbmc_small |> slice_sample(n=0)
Error: No cells found

@stemangiola stemangiola self-requested a review August 31, 2023 07:13
Copy link
Owner

@stemangiola stemangiola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

Usually when we add a functionality, or fix an error/warning, we add a unit test, to test the changes.

For exmple if we solve an error, we would

  • first add a unit test (that would fail) to test that the error happens
  • we then fix the error
  • rerun the unit test expecting no error
  • we commit the fix and the unit test

@noriakis
Copy link
Contributor Author

noriakis commented Aug 31, 2023

Thank you for your guidance! In this case, I added the unit test for slice_sample() expecting the error (expect_error). Would it be okay?

Edit: I apologize for the recurrent commit, but I thought I should have included expect_no_warning as well.

@stemangiola stemangiola merged commit 69eecf8 into stemangiola:master Aug 31, 2023
2 of 3 checks passed
@stemangiola
Copy link
Owner

Hello @wvictor14 @noriakis In the Seurat master, the slice functions produce errors in the tests. Could you please have a look?

Thanks!

@noriakis
Copy link
Contributor Author

Hello @stemangiola @wvictor14,

expect_equal(
    pbmc_small |> as_tibble() |> arrange(nFeature_RNA) |> head(n = 5) %>% pull(.cell),
    pbmc_small |> slice_min(nFeature_RNA, n = 5) |> colnames()
)

The errors seem to come from above tests in slice_min and slice_max, where the subset.Seurat by cells returns the object that is preserving the original order of the cells. The returned row numbers of cells inside the function are correct, so one option would be to adding sort() to both vectors which removes the errors.

expect_equal(
    pbmc_small |> as_tibble() |> arrange(nFeature_RNA) |> head(n = 5) %>% pull(.cell) |> sort(),
    pbmc_small |> slice_min(nFeature_RNA, n = 5) |> colnames() |> sort()
)

The arrange() function is currently deprecated, so maybe we could replace the test?

@stemangiola
Copy link
Owner

The arrange() function is currently deprecated, so maybe we could replace the test?

Agree, if you had the chance to do it, would be amazing.

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

Successfully merging this pull request may close these issues.

2 participants