R-alpha: attach( <data.frame> , pos = 1) -- does not work. detach(., save=..)

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 12 Aug 1997 18:40:55 +0200


	[R-0.50-a3]

It seems intuitive that
	  attach( .., pos = 1)
is harder
than other attach()es.

But still...

If it ever will work, it is even more important to have

detach( .... , save = "VAR.name")
	       ~~~~~~~ --------
to be working.

The documentation says that  detach(.) returns invisibly.
Therefore, we don't NEED the above  'save = ' argument to detach,
since we can work with

	VAR.name <- detach ( .... )
instead.
However, there's a little problem there, too:
if the frame has been changed it is always returned as list
(which is different from S's ``save = T'' 
 which tries to coerce to data.frame)

Otherwise, things are ok (and conform to S's behavior):


###-------  Martin Mächler, Aug.12, 1997  (0.50-a3) : -----
data(bees)
search()

attach(bees)
attach(bees[-1,])
search()#ok : ".GlobalEnv"   "bees[, -1]"   "bees"   "library:base"

length(Lcp <- log(colpos)) # 63
assign("Lcp", Lcp, pos = 2)
b1 <- detach()#-- now, b1 is a 'list' instead of a data.frame ..

length(Lcp <- log(colpos)) # 64
bb <- detach()#>>> bb is a data.frame
search()#-- as it was 'at the beginning'

data.class(bb)# "data.frame"
data.class(b1)# "list"

db1 <- as.data.frame(b1)
##>> Error: no applicable method for "as.data.frame"

## And -- as a matter of fact -- there are __NO__ methods for as.data.frame...

## The following helps:
as.data.frame.default <-
  function (x, row.names = NULL, optional = F, ...)
  data.frame(x, row.names=row.names, ...)

db1 <- as.data.frame(b1)
summary(db1) #--> ok


attach(bees, pos = 1)
search()#- just still at  pos = 2 ..
attach(bees[,-1], pos = 3) #-- works ok !
search()#ok:  ".GlobalEnv"   "bees"   "bees[, -1]"   "library:base"

detach() #-- detaches pos=2, [ NOT the last attached one; -- AS S-plus ]
search()#--  ".GlobalEnv"    "bees[, -1]"   "library:base"
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-