MicrobiomeStat
MicrobiomeStat copied to clipboard
generate_alpha_change_test_pair(): Error in `dplyr::group_by()`: ! Must group by variables found in `.data`. ✖ Column `time` is not found.
This is my script:
generate_alpha_change_test_pair(
data.obj = MicrobiomeData,
alpha.obj = NULL,
alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou"),
time.var = "TimePoint",
subject.var = "Individual",
group.var = "Treatment",
adj.vars = NULL,
change.base = 1,
alpha.change.func = "absolute change"
)
My time.var is "TimePoint". I got a error show that "Column time is not found."
I have check the script of generate_alpha_change_test_pair() function, and I see the variable time first appears on line 30; before that, it was not defined (time.var was not assigned to it).
Hi @qqwxp,
Thank you for bringing this to my attention. You're absolutely right. The script wrongly assumes a column named time instead of using the provided time.var argument to adapt dynamically. It was indeed an oversight on my part.
Here's a suggested fix for that portion of the code:
Replace:
alpha_grouped <- alpha_df %>% dplyr::group_by(time)
alpha_split <- split(alpha_df, f = alpha_grouped$time)
With:
alpha_grouped <- alpha_df %>% dplyr::group_by(!!sym(time.var))
alpha_split <- split(alpha_df, f = alpha_grouped[[time.var]])
This change ensures that the provided time.var argument is used dynamically to refer to the correct column name, adding more flexibility and robustness to the function.
I've already made this correction in the code and updated it on Github. Once it syncs, you should be able to pull the updated version and use it without this issue.
Again, I sincerely appreciate you pointing this out, and I apologize for any inconvenience caused. Please let me know if there are any further issues or if you have additional feedback.
Best regards, Chen YANG
@cafferychen777 Thanks.
Similar issues also appeared in the function generate_taxa_change_test_pair(), which ignored the user-provided subject.var parameter. @cafferychen777
Hi @qqwxp, thank you for pointing this out. I noticed the same issue with the function generate_taxa_change_test_pair() when I was revising the alpha_change last week. I believe I have addressed this problem by ensuring the function now properly considers the user-provided subject.var parameter. Please update the package to the latest version to see these changes.
I thought I had installed the latest version because there was no error when running generate_alpha_change_test_pair(), but there was still an error when running generate_taxa_change_test_pair(). I will try reinstalling it again.
Hi,
Thanks for bringing this to my attention. The discrepancy you're seeing is because I patched and committed the fix for generate_alpha_change_test_pair() first. After that, I updated generate_taxa_change_test_pair(), which explains why they have different version numbers. Please make sure to pull the latest changes for both, and if the issue persists after that, let me know and I'll look into it further.
Thanks