[Rd] Options that are local to the package that sets them

Gábor Csárdi csardi.gabor at gmail.com
Sat Nov 1 02:46:09 CET 2014


On Fri, Oct 31, 2014 at 9:20 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
[...]
> Isn't your problem really just that you want multiple sets of
> settings?  That's what settings provides.

Almost. Multiple sets of settings, set up by the same package. So
essentially I want pkgA to use different settings when called from
different packages.

E.g. imagine that my package igraph has an option that sets a color
plot plotting. Another package, qgraph sets this setting to something,
say "red". Now another package xgraph wants to set it to "green". What
I want is to use "red" when plotting through qgraph, and to use
"green" when plotting from xgraph.

igraph provides the API for setting this option, so if I just use
'settings' (or a similar technique) in igraph, then xgraph's setting
will overwrite qgraph's setting.

> pkgA would provide a class whose instances are created by the clients.
> Assuming you wrap this in a function create:
>
> inst1 <- create(a = 1, b = 2)
>
> where create sets up a settings object and does anything else
> returning the handle inst1.
>
> When you want to do something you would pass the instance to the
> function or method that actually carries it out.  This could be done
> with any OO system in R without settings but if you are looking for an
> options type interface which I thought you were then you might be able
> to leverage that package.

You are right, this should work. I would like to avoid passing the
settings object to each and every igraph function, though. (Would need
to update 500+ functions.) But that does not seem to be possible,
unless I start messing with the call stack.

G.



More information about the R-devel mailing list