Reading "R Internals" made me believe that R_UnboundValue was a placeholder
that would be skipped over in variable lookup. viz. the section of R
Internals "Hash tables" says "items are not actually deleted but have their
value set to R_UnboundValue.", which seems to align with what I read in
envir.c.

So, I reasoned, if I have a function that returns R_UnboundValue,
like so:

unbound_value <- function() .Call("unbound_value")

SEXP unbound_value() {
  return R_UnboundValue;
}

then calling

x <- unbound_value()

ought to make "x" unbound. [spare me from saying this is a bad idea--I'm
just trying to understand what's going on.]

But it seems to only work partially --  If a name "x" is bound to
R_UnboundValue, exists("x") returns TRUE, though sometimes name lookup
proceeds as you'd expect:

> x <- 5; local({x <- 6; rm("x"); exists("x", inherits=FALSE)})
[1] FALSE
> x <-5;  local({x <- 6; x <- unbound_value(); exists("x", inherits=FALSE)})
[1] TRUE
> x <-5;  local({x <- 6; x <- vadr:::unbound_value(); x})
[1] 5

but assigning unbound on the global namespace blocks name lookup from going
up the search path:

> find("HairEyeColor")
[1] "package:datasets"
> HairEyeColor <- unbound_value()
> class(HairEyeColor)
Error: object 'HairEyeColor' not found
> rm("HairEyeColor")
> class(HairEyeColor)
[1] "table"

I've been looking through the source in envir.c but I haven't found what
would make rm("x") have a different effect from x <- unbound_value(). Any
hints?

Peter

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to