[Rd] [External] DOCS/BUG?: opts <- base::.Options is *not* a copy

iuke-tier@ey m@iii@g oii uiow@@edu iuke-tier@ey m@iii@g oii uiow@@edu
Thu Feb 24 14:22:54 CET 2022


On Thu, 24 Feb 2022, Henrik Bengtsson wrote:

> Hi, is the following a non-documented feature or a bug:
>
> $ R --quiet --vanilla
> opts <- base::.Options
> opts[["abc"]]
> #> NULL
> options(abc = 42)
> opts[["abc"]]
> #> [1] 42
>
> I would have expected that 'opts' would be a *copy* of base::.Options
> that is not affected by later changes to base::.Options.  FWIW, the
> same happens if we try with:
>
> opts <- .BaseNamespaceEnv[[".Options"]]
>
> I don't think lazy evaluation is involved, because I evaluate
> opts[["abc"]] above.
>
> The only thing help(".Options") says is:
>
> Note:
> For compatibility with S there is a visible object .Options whose
> value is a pairlist containing the current options() (in no particular
> order). Assigning to it will make a local copy and not change the
> original. (Using it however is faster than calling options()).

You are misreading what this says. As with any assignment to an object
that has other references, the assignment will create a local copy
before mutating. It does not say that referencing the object makes a
copy. So there is no inconsistency.

That options() modifies the value of an object with multiple
references is not ideal, but changing that while maintaining .Object
as a regular variable is probably more trouble than it is worth. It is
probably time to work towards deprecating .Options (maybe turning it
into an active binding that does make a copy). At the very least
discouraging its use in the help file.

Other that changing the docs I doubt this will ever get high enough on
anyone's priority list to get done.

Best,

luke

>
> This behavior goes back to at least R 2.15.0.
>
> /Henrik
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney using uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



More information about the R-devel mailing list