[R-sig-DB] Add a "dbSendUpdate" function to DBI?

Paul Gilbert pg||bert902 @end|ng |rom gm@||@com
Sat Sep 6 19:44:17 CEST 2014



On 09/05/2014 02:40 AM, Prof Brian Ripley wrote:
> On 04/09/2014 22:22, Paul Gilbert wrote:
>>
>>
>> On 09/04/2014 03:15 PM, Hadley Wickham wrote:
>>>> It is the "If the API" part that I worry about. For example
>>>>
>>>>> success(warning("warn"))
>>>> Warning message:
>>>> In doTryCatch(return(expr), name, parentenv, handler) : warn
>>>>> is.logical(success(warning("warn")))
>>>> [1] FALSE
>>>> Warning message:
>>>> In doTryCatch(return(expr), name, parentenv, handler) : warn
>>>>>
>>>>
>>>> So then every package writer trying to build on DBI has to write a
>>>> wrapper
>>>> that anticipates the exceptions that may be thrown. This becomes even
>>>> more
>>>> difficult when different db drivers, different OSes, and different
>>>> servers
>>>> are involved.
>>>
>>> I'm not sure I follow, because we hadn't talked about warnings. I
>>> would not expect that DBI backends to through warnings instead of
>>> errors.
>>
>> Well, in my experience my programs usually fail for the reasons I don't
>> expect rather than the ones I do expect. I guess that is mainly why I
>> like a function that returns a logical, I know what to expect.
>>
>>>
>>>> Given the philosophical constraint I think I would generally prefer the
>>>> function that is guaranteed to return a logical. The other wrapper is
>>>> easy
>>>> to write too.
>>>
>>> But it's fundamentally more dangerous. If all modification functions
>>> return TRUE or FALSE and you don't explicit check the return value, it
>>> is extremely easy to create invalid code. The same is not true for
>>> errors.
>>
>> If I understand your logic correctly, you would recommend using
>> library() rather than require() when one of them is necessary in a
>> function? Or rather, you would not provide require(), only library()? (I
>> always use require(), and check the return value.) It is, of course,
>
> You are wrong: see
> http://cran.r-project.org/doc/manuals/r-patched/R-exts.html#Suggested-packages
>

Thanks for pointing this out, I see I have some updating to do.

As to the comparison in my comment, I don't think you would say that 
library() is preferred to require() as a programming interface, for 
example in a function in a vignette, even though requireNamespace() 
would be even better.

Paul

>
> Code in functions should not change the search path, and it does not
> achieve what most people seem to think it does.
>




More information about the R-sig-DB mailing list