[R] Why a list of NULL's are reduced to NULL?

Peng Yu pengyu.ut at gmail.com
Fri Dec 11 19:24:43 CET 2009


On Fri, Dec 11, 2009 at 12:05 PM, hadley wickham <h.wickham at gmail.com> wrote:
>> A very common situation is that the users don't know all the possible
>> return types of 'some_third_party_function()'. If the users don't know
>> all the return types, he/she can not make sure the return type of
>> function(x) {...} be always the same. How do you deal with this case?
>
> It's not that common.  It's pretty bad practice to return different
> types from a function depending on the input parameters.  In many
> languages this isn't even possible.

I know this is a bad practice. But R doesn't have a way to forbid such
thing happen. To program defensively, I have to test even uncommon
case, unless it is impossible. When you use a third party software in
your code, do you just ignore the possibility that a function could
return different types?

> The solution is to write a function that takes the output from the
> first function, inspects it, and coerces all possibilities to the same
> type.

How do you figure out all the possibilities?




More information about the R-help mailing list