Missing() vs NULL

Should I use if (missing(arg)) or if(is.null(arg)) to handle a non specified argument? What's considered good practice?
My argument against missing is that I can't use it outside a function. Argument for NULL is that everyone can see that it defaults to NULL in the documentation. missing looks cooler in the function. When should I choose missing over NULL?

There is some overlap, but they are giving different information, so it depends what you need to know. There might be use cases where you want to know both.
If someone calls the function and relies on a default param value, missing will show true even though the param vale is not null.


1 Like

Argument for NULL, the user can see that he does not need to specify a value for the arg since there is a default behavior which nobody can see from missing. Maybe missing is useful for .... and I guess missing shouldn't be used by "internal" helper functions which are only called other functions and not by the user directly. In case you run a function with a lot of values it might be better to use NULL rather than missing due to your point @nirgrahamuk. Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.