-
Notifications
You must be signed in to change notification settings - Fork 10
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
revise unit tests tidySingleCellExperiment
#79
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, sorry to be a pain. Since we are changing the test already, could I please ask to use base-R pipe?
I am trying to get rid of dplyr pipe wherever I can.
R/dplyr_methods.R
Outdated
@@ -275,12 +274,13 @@ mutate.SingleCellExperiment <- function(.data, ...) { | |||
rename.SingleCellExperiment <- function(.data, ...) { | |||
|
|||
# Check that we are not modifying a key column | |||
cols <- tidyselect::eval_select(expr(c(...)), colData(.data) %>% as.data.frame()) | |||
|
|||
df <- as_tibble(.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be, I believe more inefficient than getting colData directly, as it integrates also PC, UMAP etc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe could you help me understand the nature of this 3-line change? So I can have a bit more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so I came across this while writing unit tests. Basically, if you try with the current version something like rename(sce, new_name=.cell)
, it will pass without an informative warning, but then fails because .cell
is not an actual column.
I think it works for other functions, but not here, because the syntax is rename(..., new=old)
(unlike most other verbs, e.g., mutate(..., new=value)
, we want to block the OLD columns here, I think?), so cols
from using eval_select()
will correspond to the left-hand side names, not the ones being changed (right-hand side).
What made it clear to me was adding a print(cols)
in line 279 and see what's happening vs. what happens with using eval_rename()
instead (which returns indices)... Of course, would be great to find a way without using as_tibble()
, but I couldn't come up with one :/ Though if we want to limit cost here, we could just do, e.g., as_tibble(.data[, 1])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I am not sure if maybe you head in mind doing both, i.e., not letting someone rename a column to .cell
, but also not trying to rename .cell
? I that case, we'd need a combination of both eval_select()
and something else like the above, but more elegantly perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
So .cell is an immutable column.
A solution can be
- colData() |> as_tibble(rownames = EXISTING_INTERNAL_FUNCTION_THAT_ENCODES_CELL_COLNAME)
- rename
- drop .cell column so it's untouched
- warning ("tidySingleCellExperiment says: ...") If .cell is in the query (there could be multiple columns in the query)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I am not sure if maybe you head in mind doing both, i.e., not letting someone rename a column to
.cell
, but also not trying to rename.cell
?
Pretty much this.
Thanks @HelenaLC ! That's great. I left 3 comments with some little changes or explanations. Love the PR. |
Yes, absolutely! I actually prefer not using any pipes internally, but didn't want to fiddle too much with the style. But agreed, I'll use base R pipes instead of (Side note: perhaps we could have a brief chat re linting. I am mainly focusing on Bioc-guidelines plus some simplifications, and I am leaning towards more base R vs. tidy-style, which I think would make things cleaner (and briefer) in many (not all) cases, at least internally...) |
Base pipes after R evaluation they disappear. It is just a visual-coding aid. So makes no difference for R.
Yes thta's a more complex topic. We could discuss about that. It is good to respect standards, but we are practically contributing to changing them. And it is becoming evident to many. When I think about standards, I try to imagine what they will be in 5-10 years. Things are moving fast :) Personal opinion: I think pipes make the code more readable in virtually all cases. |
Absolutely. I did not mean to speak against pipes in general (illusional or not). Currently, I am trying my best to keep them for workflow-like operations, where they do make things easier to write and read. And only not use them when it really is a lot easier to follow (in my opinion), e.g., I struggled more to understand things like Independent of personal opinions / style-preferences, my case against using Aaanyways, hoping to finish a first iteration first (towards a clean-ish *One example re the above, |
true |
Just wondering before I finalize the next one, what's happening with this PR? Is there something you'd like to be changed explicitly (and perhaps kept for another PR) before merging? |
Hello @HelenaLC, is the above still pending? I think this is the last part missing, to be modified fro your PR. All the rest look fantastic. |
Alright. I implemented a fix that I think does what it should, i.e., special columns ( |
Great, thanks for that! We were not getting the expected error, so I slightly changed the logic. Also, in the future, we can check Thanks for this PR! |
tidySingleCellExperiment
rename()
(renaming special columns, e.g.,.cell
, previously gave an error that the column doesn't exists, but should work as intended now)pbmc_small
) viaBiocGenerics::updateObject()
) as it was outdated, causing some tests to fail (due to differences in internal metadata)