From joshmobrien at gmail.com  Fri Mar 22 20:43:05 2013
From: joshmobrien at gmail.com (Josh O'Brien)
Date: Fri, 22 Mar 2013 12:43:05 -0700
Subject: [Rd] Why does typeof() modify an object's "named" field?
Message-ID: <CAOwKfPSc8X8qNCVmieCLLnaLMo2k+GmH8dHHUmrYt+1AdPDcEg@mail.gmail.com>

Hello,

Doing typeof() on an object appears to reset the "named" field in its
sxpinfo header to 2, which can change the way that subsequent
subassignment operations are carried out:


X <- 1:5e7
.Internal(inspect(X))
# @4eeb0008 13 INTSXP g0c7 [NAM(1)] (len=50000000, tl=0) 1,2,3,4,5,...
system.time(X[1] <- 9L)
#    user  system elapsed
#       0       0       0


typeof(X)

.Internal(inspect(X))
# @4eeb0008 13 INTSXP g1c7 [MARK,NAM(2)] (len=50000000, tl=0) 9,2,3,4,5,...
system.time(X[2] <- 9L)
#    user  system elapsed
#    0.16    0.08    0.23

Some other functions that query the nature of an object (e.g. class(),
length(), attributes()) do not modify the object's "named" field. Is
there a reason that typeof() should?


(Possibly of interest is this somewhat related thread on Stack
Overflow: http://stackoverflow.com/questions/15559387/operator-in-rstudio-and-r/15559956#15559956
).



[Rd] Why does typeof() modify an object's "named" field?
Josh O'Brien