'Minimal distance between random points in r

I am trying to make a random sample of points on a shape layer composed of multipolygons. I use for that the st_sample function of package sf. I get my sample with the desired number of points but I also want these points to have a minimum distance between them. I can't find an argument in the st_sample function that allows me to do this easily. Do you have a solution?

I put you my code that works with any shapefile:

# Clean environment 
# rm(list = ls())

# Import packages
library(sf)

# Import data
shp = st_read("Path_to_my_shp")

# Random sampling
pts.sample = st_sample(shp,  100, "random")

#Need to minimal distance between points

Thank you for any help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source