Add function

This update adds the actual function to the template R script.