`sapply` is a bit dangerous inside functions - use `vapply` instead