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
Fix tidy.prcomp labels for loadings and scores matrices #910
Fix tidy.prcomp labels for loadings and scores matrices #910
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.
For consistency of returning integer when there are no rownames in the matrices, this could be added in.
Thanks for pointing this out @tavareshugo! Should I consider this PR ready to review? How should I interpret your review comments/suggestions? |
Hi @simonpcouch, thanks for having a look at this. I've committed my previous suggestions (i.e. for consistency with previous versions it returns labels as integer if rownames of those matrices are missing). I've also made a new commit adding my details to the contributors and a note to |
Thanks for your patience with this, @tavareshugo. This code looks great to me, so I'll go ahead and resolve conflicts and merge! Much appreciated. |
thanks a lot @simonpcouch, I'm glad I could help a little bit with the package |
This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
Hi,
I think there was a bug in
tidy.prcomp()
related to this commit, which moved code from usingdplyr::gather()
todplyr::pivot_longer()
. These two functions sort the output tibble in different ways, and so the labels being added withrep()
were wrong when usingtidy(x, matrix = "scores")
andtidy(x, matrix = "loadings")
.Here's an example (using broom v0.7.0):
Results in
The result we want is rather:
I guess I could have just changed
rep()
to useeach = ncomp
rather thantimes = ncomp
.However, I think my fix is perhaps a bit simpler to read and more robust to future changes in how
pivot_longer()
sorts output. I took advantage oftibble::as_tibble()
ability to add rownames as columns, and this works even ifrownames(x)
isNULL
.I hope the PR is helpful. (And thanks for the amazing package!)