complete.R function