Bug 15781 - options(foo = NULL) does not return the previous value
Summary: options(foo = NULL) does not return the previous value
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.1.0
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-04-26 03:15 UTC by Russ Lenth
Modified: 2014-04-26 17:20 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Russ Lenth 2014-04-26 03:15:25 UTC
I have found that if one wants to un-set an option, say "foo",
then options(foo = NULL) does not return the previous value of foo.
I do not know if this bug is unique to Windows or not.

Here is a demo -- I wrote a little function that sets foo and
returns its previous value...

setFoo <- function(x) {
    prev <- options(foo = x)
    cat("Previous foo:\n")
    prev$foo
}

# Now here are some results (in the order conducted)

> getOption("foo")
NULL

> setFoo("bar")
Previous foo:
NULL
### This is correct

> setFoo("bear")
Previous foo:
[1] "bar"
### This is correct

> setFoo(NULL)
Previous foo:
(function () 
{
    .rs.recordTraceback(userOnly)
})()
####### This is wrong. it should be "bear" #######
### The result seen here turns out to be equal to getOption("error")
### when running RStudio.

> setFoo("bare")
Previous foo:
NULL
### This is correct again

### My system information is shown below. I also tried this on
R-devel (2014-04-19 r65413) (NOT within RStudio) and obtained 
different wrong results from options(foo = NULL)

#-----------------------------------------------
> R.Version()
$platform
[1] "x86_64-w64-mingw32"

$arch
[1] "x86_64"

$os
[1] "mingw32"

$system
[1] "x86_64, mingw32"

$status
[1] ""

$major
[1] "3"

$minor
[1] "1.0"

$year
[1] "2014"

$month
[1] "04"

$day
[1] "10"

$`svn rev`
[1] "65387"

$language
[1] "R"

$version.string
[1] "R version 3.1.0 (2014-04-10)"

$nickname
[1] "Spring Dance"
Comment 1 Russ Lenth 2014-04-26 03:25:21 UTC
Realizing it was silly to write a function for this. Another test...

#-------------------------------------------------------------------
> print(options(foo = "bar"))
$foo
NULL

> print(options(foo = "bear"))
$foo
[1] "bar"

> print(options(foo = NULL))
$foo
function (url, height = NULL) 
{
    if (!is.character(url) || (length(url) != 1)) 
        stop("url must be a single element character vector.", 
            call. = FALSE)
    if (!is.null(height) && (!is.numeric(height) || (length(height) != 
        1))) 
        stop("height must be a single element integer vector.", 
            call. = FALSE)
    invisible(.Call("rs_viewer", url, height))
}
<environment: 0x0000000008bc3680>

> print(options(foo = "bare"))
$foo
NULL

#-------------------------------------------------------
Note I got an entirely different wrong result with a fresh start of RStudio
Comment 2 Duncan Murdoch 2014-04-26 17:20:22 UTC
This is a simple off-by-one error in the reporting; you saw the value of the previous option in the internal list.

Will fix in R-devel and R-patched.