Code to aid ETL in R