Functions amended to call R functions correctly