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

Add slice functions #90

Merged
merged 9 commits into from
Aug 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/dplyr_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,10 @@ slice_sample.SingleCellExperiment <- function(.data, ..., n=NULL,
select(!!c_(.data)$symbol) %>%
count(!!c_(.data)$symbol)

.max_cell_count <- ifelse(nrow(count_cells)==0, 0, max(count_cells$n))

# If repeated cells due to replacement
if (count_cells$n |> max() |> gt(1)){
if (.max_cell_count |> gt(1)){
Copy link
Owner

Choose a reason for hiding this comment

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

looks good, does the warning appear in tidyseurat as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for checking. Seems to be yes, although it results in an error. Should I also replace the part for tidyseurat?

> pbmc_small |> slice_sample(n=0)
Error: No cells found
In addition: Warning message:
In max(count_cells$n) : no non-missing arguments to max; returning -Inf

Copy link
Owner

Choose a reason for hiding this comment

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

@noriakis Yes, please fix the error in tidyseurat and write a unit test for it.

If this is relative to an empty object I thought you had a stop() call already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your reply. The error is related to an empty object coming from stop() call in subset.Seurat() as you pointed out, so I will just fix the warnings.

message("tidySingleCellExperiment says: When sampling with replacement",
" a data frame is returned for independent data analysis.")
.data |>
Expand Down