metacell icon indicating copy to clipboard operation
metacell copied to clipboard

mcell_mc_hierarchy while condition

Open baj12 opened this issue 1 year ago • 1 comments

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.

baj12 avatar Mar 05 '23 12:03 baj12

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

pujaltes avatar Apr 03 '23 14:04 pujaltes