Slightly updated R code- mainly about attaching