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

Henrik Bengtsson henr|k@bengt@@on @end|ng |rom gm@||@com
Thu Feb 24 03:58:00 CET 2022


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()).

This behavior goes back to at least R 2.15.0.

/Henrik



More information about the R-devel mailing list