title: R3.4 Viewing object reference counts ("NAMED")
body: <p>Until v3.5 (I think), R had a poor-man's reference count facility called NAMED. In a nutshell, an object's NAMED attributed can hold 3 values:</p>
  <ul>
  <li>0   - the object is not named (i.e., not referenced and can be
  garbage collected)</li>
  <li>1   - the object is referenced by a single name (and so can be modified in place)</li>
  <li>2   - a.k.a &quot;many&quot;: the object is referenced by many names. If it changes - needs to be copied. If a name is removed the NAMED
  attribute would <em>not</em> decrement.</li>
  </ul>
  <p>(some more details <a href="https://developer.r-project.org/Refcnt.html" rel="nofollow noreferrer">here</a>).</p>
  <p>I'm trying to view this attribute from R, and am experimenting both with <code>pryr::refs(x)</code> and <code>.Internal(inspect(x))</code>. I can't understand the results of either.</p>
  <pre><code>tst &lt;- function(x) {
    print(pryr::refs(x))   # 0
    .Internal(inspect(x))  # 2
  
    x[5] &lt;- as.integer(14)
    print(pryr::refs(x))   # 1
    .Internal(inspect(x))  # 1
  
    y&lt;-x
    print(pryr::refs(x))   # 2
    .Internal(inspect(x))  # 2
  }
  a &lt;- 1:100
  tst(a)
  
  # [1] 0
  # @5646a302a020 13 INTSXP g0c7 [NAM(2)] (len=100, tl=0) 1,2,3,4,5,...
  # [1] 1
  # @5646ab296810 13 INTSXP g0c7 [NAM(1)] (len=100, tl=0) 1,2,3,4,14,...
  # [1] 2
  # @5646ab296810 13 INTSXP g0c7 [NAM(2)] (len=100, tl=0) 1,2,3,4,14,...
  </code></pre>
  <p>Can anyone shed some light on what's going on here? Is there a better way to inspect an object's references?</p>