completed code in R file