Recently our lecturer taught us about the apply family in R. As I was reviewing my notes I was puzzled on one part regarding the application of sapply versus vapply as the lecturer indicated they are essentially the same.
My understanding of sapply is that it attempts to simplify the argument it is provided and return this to the user. However, it doesn't always return a simplified value due to the input vector being of a variable length (I didn't fully understand this point). However, sapply won't point this out.
With vapply however, you don't run the risk of having a vector fail to be simplified without you knowing as it will throw an error message if this is the case and you have to specify a return type value.
In that case, my understanding would be that vapply would be the preferred option over sapply as it is the safer option. I asked my tutor if this was the case and he said it all came down to personal preference.
Is this truly the case - that vapply and sapply are inherently the same function except one is more fail-safe than the other? Or are there certain situation(s) where you would want to explicitly use vapply over sapply and vice versa?
I have read the following SO which has helped shed some light on the differences from a performance perspective: Why is `vapply` safer than `sapply`?
Edit: I have re-read the why-is-vapply-safer-than-sapply link but I don't think I'm fully across this. My question still stands in that, Is there a situation where sapply would be more suitable than vapply? Does such a situation exist?
Thank you.