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?
Hi @mikejiang,
I quite often have to extract
GatingHierarchies
when using certainflowWorkspace
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: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 aGatingHierarchy
. 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 withx[[1]]
? Ifx
is aGatingSet
then aGatingHierarchy
will be returned and ifx
is aGatingHierarchy
then aGatingHierarchy
will be returned. Either way I get theGatingHierarchy
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?