Useful R functions for ND DSG