Completed functions in R file.