distance function. Code is shown in Rmd by printing functions. keep.source=TRUE