R functions: how to return the results correctly

Can't say much without a reproducible example, called a reprex. The object whole is missing, for one.