RGLab / flowWorkspace

flowWorkspace
GNU Affero General Public License v3.0
44 stars 21 forks source link

Subsetting GatingSet & GatingHierarchy #359

Closed DillonHammill closed 3 years ago

DillonHammill commented 3 years ago

Hi @mikejiang,

I quite often have to extract GatingHierarchies when using certain flowWorkspace APIs. I used to maintain a number of distinct methods for these operations but I am working to remove a lot of these by instead including class checks as below:

# x is a GatingSet or GatingHierarchy
if(class(x, "GatingHierarchy")){
gh <- x
} else if (class(x, "GatingSet")){
gh <- gs[[1]]
}
# supply gh to GatingHierarchy API
gh_generate_template(gh)

Of course, this works fine but I was looking for more concise way of doing this when I stumbled upon the fact that subsetting a GatingHierarchy still returns a GatingHierarchy. I was expecting an out of bounds error, so this is fantastic! I was just wondering how safe it is to replace the code above simply with x[[1]]? If x is a GatingSet then a GatingHierarchy will be returned and if x is a GatingHierarchy then a GatingHierarchy will be returned. Either way I get the GatingHierarchy that I need and I can avoid the if else statements.

Is this behaviour likely to be maintained or should I resort to if else statements instead?

mikejiang commented 3 years ago

Yeah, it should be fine in foreseeable future.

DillonHammill commented 3 years ago

Thanks @mikejiang!