[R-pkg-devel] Recommendations about adding options to a package in order to change default values of some functions on-the-fly
David Hugh-Jones
d@vidhughjone@ @ending from gm@il@com
Thu Sep 6 18:24:41 CEST 2018
Hi all,
A simple solution - if indeed you want to go down this route - is to use
options() and getOption(), ensuring all options are namespaced, e.g. by
prefixing them with the package name.
David
On Thu, 6 Sep 2018 at 17:15, Alexandre Courtiol <
alexandre.courtiol using gmail.com> wrote:
> Dear Samuel,
>
> Many may object (for good reasons) that adding options would clash with
> functional paradigm, but it is possible.
> I don't know about the least worse practice but as far as I would do it,
> you could:
>
> 1. directly write and then read elements in the (hidden) list .Options that
> is present in the global environment:
> options(test = "blabla") ## add element in .Options
> .Options$test ## read element (for use in your own function)
>
> 2. you could also create your own alternative to options(), as ex:
> https://github.com/courtiol/IsoriX/blob/master/IsoriX/R/options.R
> Option 2 has the benefits of not risking conflict with existing names in
> .Options and it would thus also not mess up the way other packages may
> work.
> Option 1 uses what is already in place.
>
> I hope this help,
> Best
>
> Alex
>
> On Thu, 6 Sep 2018 at 17:18, Samuel <samuel.granjeaud using inserm.fr> wrote:
>
> > Hi,
> >
> > I would like to change the default value of some arguments of some
> > functions in a package of mine. I don't want to change explicitly the
> > calls in the many scripts that have been written. For example, I would
> > to change the delimiter in all write.mytable() without changing any
> > calls it and without changing the default value currently assigned to
> > that delimiter in the declaration of this function. What I would like is
> > to add a command at the beginning of the scripts that says "since now,
> > the delimiter is ;".
> >
> > I am thinking about setting global options that those functions will
> > read and use to overwrite the default values. Of course the
> > write.mytable function has to be modify to exploit these settings, but
> > none of the scripts. I think about something similar to the par() and
> > options() functions.
> >
> > I noticed the settings package, but I would like to know if there is a
> > simple and recommended solution without adding any dependency.
> >
> > Hope my question is clear.
> >
> > Thanks for any advice,
> > Samuel
> >
> > ______________________________________________
> > R-package-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >
>
>
> --
> Alexandre Courtiol
>
> http://sites.google.com/site/alexandrecourtiol/home
>
> *"Science is the belief in the ignorance of experts"*, R. Feynman
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list