Home made R function