Fille din function code, tested and validated in RStudio