R: put tests in the package, and provide a function to run them. Closes issue #485.