On Fri, Dec 11, 2009 at 12:05 PM, hadley wickham <h.wick...@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?

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to