Replication R script