Consider the following raster with two categories and a DEM (numeric raster), I'd like to compute the elevation difference along the border (closest pixel) of those two categories, it doesn't matter on which side of the border the result is stored. I've checked r.neighbors but it's not category-aware. It's of little matter what it does in corners, where there are two closest pixels.
I'd like to keep it in GRASS (maybe python) because I'm making lots of spatial stats through rgrass7.