Very fast version using rtree::countWithinDistance().

count_within_detail(csd, phenotypes = NULL, radii)

Arguments

csd

Cell seg data.

phenotypes

Optional list of phenotypes to include. If omitted, will use unique_phenotypes(csd). Counts are from each cell to each phenotype.

radii

The radius or radii to search within.