add R scripts and Rd documentation