Code written in R