title: Copy-on-modify behaviour different between `c(1L, 2L, 3L)` and `1:3`
body: <p>I'm reading <a href="https://adv-r.hadley.nz/" rel="noreferrer">Advanced R</a> by Hadley Wickham, trying to solve <a href="https://adv-r.hadley.nz/names-values.html#exercises-1" rel="noreferrer">exercise 2</a> from section 2.3.6 about copy-on-modify:</p>
  <blockquote>
  <p>Explain why <code>tracemem()</code> shows two copies when you run this code. Hint: carefully look at the difference between this code and the code shown earlier in the section.</p>
  <pre><code>x &lt;- c(1L, 2L, 3L)
  tracemem(x)
  
  x[[3]] &lt;- 4
  </code></pre>
  </blockquote>
  <p>(The previous code changed one element in a list of doubles to another double, yielding only one copy.)</p>
  <p>In the <a href="https://advanced-r-solutions.rbind.io/" rel="noreferrer">Advanced R Solutions</a> by Grosser and Bumann <a href="https://advanced-r-solutions.rbind.io/names-and-values.html#copy-on-modify" rel="noreferrer">they explain</a> that the second copy is due to type coercion, from integer to double. They do not define <code>x</code> as <code>c(1L, 2L, 3L)</code>, but use <code>x &lt;- 1:3</code>, which I thought was equivalent (comparing them using <code>identical</code> also returns <code>TRUE</code>). However, running the above code (on my end) only yields one copy, but running the following code yields two copies:</p>
  <pre><code>x &lt;- 1:3
  tracemem(x)
  
  x[[3]] &lt;- 4
  </code></pre>
  <p>Running this code also yields two copies:</p>
  <pre><code>x &lt;- c(1L, 2L, 3L)
  typeof(x)
  tracemem(x)
  
  x[[3]] &lt;- 4
  </code></pre>
  <p>For example replacing <code>typeof</code> with <code>class</code> only yields one copy, but replacing it with <code>mode</code> or <code>pryr::otype</code> yields two copies. But simply printing <code>x</code> out instead yields one copy.</p>
  <p>So what is the difference between <code>c(1L, 2L, 3L)</code> and <code>1:3</code>, and why do calling some but not all of the above functions alter the behaviour?</p>
  <p>I get the same behaviour running the code from PowerShell using <code>Rterm</code> and in the console in RStudio.</p>