changed R function