Skip to content

decorating API in R

1 message · Barry Rowlingson

#
On Fri, Nov 9, 2012 at 9:10 PM, Tom Roche <Tom_Roche at pobox.com> wrote:
You can pretty much do exactly that. There's no reason why your
package can't have:

ncvar_add = function(x,y,datavar){
  ncdf4::ncvar_add(x,y,something with datavar, etc etc with the custom
ioapi stuff)
}

 ie, your ncvar_add plays with its args and then calls the ncvar_add
in ncdf4. The problems are then:

 * If a user loads both packages, then one function will mask the
other - you'll get a warning, and to use the masked one you have to do
packagename::ncvar_add(foo)

 * You may now confuse users. Normally with OO systems you could have
some signature that decided which of a method to call, but you are
going to end up having to superclass the ncdf object... maybe...
horrible...
I'm not sure you can 'extend' an R package with another package - you
certainly cant just define 'package foo extends package bar' in any
way and expect foo::anything to call bar::anything.

 The conventional thing for you to do would be to write a new package
that depends on ncdf4, has functions with unique names, and then calls
ncdf4 package functions to do the ncdf4 level things. Anything wrong
with that?


Barry