embedded R function not working