added demo; added a R wrapper around the c++ function to do some error checking and the like