tanaylab / metacell

Metacell - Single-cell mRNA Analysis
https://tanaylab.github.io/metacell
Other
109 stars 30 forks source link

mcell_mc_hierarchy while condition #84

Open baj12 opened 1 year ago

baj12 commented 1 year ago

In the mcell_mc_hierachy function you are using (around line 108 of mc_hierarchy.r)

while (j != -1 & cells[j] < mincells) {

I got the following error message:

Error in while (j != -1 & cells[j] < mincells) { : 
  the condition has length > 1

changing the code to

while (j != -1 && cells[j] < mincells) {

resolved the issue.

This happens when j==-1 and cells is a vector of length >1. The "&" evaluates all conditions, while "&&" would break already if the first is not met and also compare only the first incident of cells.

It would be great if you could comment on why you chose the "&" instead of "&&"

Thanks for your great tool.

pujaltes commented 1 year ago

The issue is the new version of R (>4.2) now results in an error when passing multiple conditions. Previously you would only get a warning.

See: https://stackoverflow.com/questions/72090706/new-error-no-first-element-being-used-when-condition-has-length-1