R script to collect data