add function to r