title: Getting the name of object passed to `print` when calling object directly (not expressing the `print` function)
body: <p>I'm trying to define the print method for my new object and use the name of the object passed to <code>print</code> using <code>deparse(substitute(y))</code>. This works perfectly using the <code>print</code> function explicitly:</p>
  
  <pre><code>obj &lt;- structure(list(x = 1), 
                   class = "new_obj")
  
  print.new_obj &lt;- function(y){
    cat("New object name:\n")
    print(deparse(substitute(y)))
  }
  
  print(obj)
  # New object name:
  #   [1] "obj"
  </code></pre>
  
  <p>But when the object is called by name on its own the resulting <code>print</code> function doesn't detect the name:</p>
  
  <pre><code>obj
  # New object name:
  #   [1] "x"
  </code></pre>
  
  <p>Is there a standard way to change the behaviour of the implicit call to <code>print</code> when passing an object name on its own?</p>
  
  <p>EDIT: have changed the function argument to <code>y</code> to represent object being passed, to demonstrate that "x" is returned no matter what in the second call.</p>