I have a DEM raster and a list of SpatialPointsDataFrames (data available here https://drive.google.com/open?id=1ERFdsqDGLH1a_FbxwawE_gPm0Au0Q9vT).
EDIT: (with regard to @Spacedman's comment)
I want to calculate the smallest N for each data point such that the raster values in an NxN square around each SpatialPoint's square have an elevation range (max-min) >= 15metres. It should look something like the picture below, where the brown raster cell is the one with a SpatialPoint inside and the blue line represents the extent of the NxN square.
I've looked at the help for the raster:focal function as proposed by @JeffreyEvans, but I don't see any possibilities to input my SPDF as source for the focal points.