Added contents from baad/R. More roxygen comments, cleaning, moving.