Change R options only inside a package
El d?a 15/07/2013 a las 13:30, Duncan Murdoch
<murdoch.duncan at gmail.com> escribi?:
On 13-07-15 5:27 AM, Helios de Rosario wrote:
Hi, What should I do if I want to use "non-default" R-options for the functions inside a package, but not affect the options of the rest
of
the session? Specifically, I'm thinking of using "sum contrasts"
instead
of the default, in functions like "lm", etc. when they are called
by
other functions in a package.
[...]
I'd recommend that in your own functions that need this, you put this
at
the beginning:
saveOpts <- options(contrasts = c("contr.sum", "contr.sum"))
on.exit(options(saveOpts))
This means that the options will be changed just for the duration of
the
call. If there are situations where users might not want this new default, make the new value a default of a function argument.
Thank you very much. I was not aware of the on.exit function. Helios De Rosario INSTITUTO DE BIOMEC?NICA DE VALENCIA Universidad Polit?cnica de Valencia ? Edificio 9C Camino de Vera s/n ? 46022 VALENCIA (ESPA?A) Tel. +34 96 387 91 60 ? Fax +34 96 387 91 69 www.ibv.org Antes de imprimir este e-mail piense bien si es necesario hacerlo. En cumplimiento de la Ley Org?nica 15/1999 reguladora de la Protecci?n de Datos de Car?cter Personal, le informamos de que el presente mensaje contiene informaci?n confidencial, siendo para uso exclusivo del destinatario arriba indicado. En caso de no ser usted el destinatario del mismo le informamos que su recepci?n no le autoriza a su divulgaci?n o reproducci?n por cualquier medio, debiendo destruirlo de inmediato, rog?ndole lo notifique al remitente.