See vignette 7, “Spherical geometry in sf using s2geometry” of package sf.