From m1jjh00 at frb.gov  Fri Feb 23 17:23:53 2007
From: m1jjh00 at frb.gov (Jeffrey J. Hallman)
Date: Fri, 23 Feb 2007 11:23:53 -0500
Subject: [Rd] How to override functions in namespaces?
In-Reply-To: Message from Prof Brian Ripley <ripley@stats.ox.ac.uk> of "Thu,
	22 Feb 2007 23:27:56 GMT."
	<Pine.LNX.4.64.0702222318430.27682@gannet.stats.ox.ac.uk> 
Message-ID: <20070223162353.BED301F7B0@mail.rsma.frb.gov>

Prof Ripley,

Thanks to both you and Duncan Murdoch, who replied with similar advice.
Your suggestion to use get("askForString", pos = 1)() in my ssh()
function does what I want whether package B is attached or not.

Jeff

Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
  br> On Mon, 12 Feb 2007, jhallman at frb.gov wrote:
  >> In package A I have askForString(), which asks the user for a string.
  >> Also in package A I have defined ssh(), which calls askForString().
  >> 
  >> Package B has package A as a prerequisite.
  >> 
  >> In package B I redefine askForString() to take advantage of a nicer user
  >> interface made available by B, namely the Emacs mini-buffer prompt.
  >> 
  >> Packages B and A are both on the search path, with B ahead of A.  If I
  >> call askForString() at the command prompt, I get the version from B.
  >> But the version used by ssh() depends on whether or not package A has a
  >> namespace. If so, ssh() (defined in A) always uses the A version of
  >> askForString().  How can I get ssh() to use the B version of
  >> askForString()? Or am I going about this all wrong?

  br> That is one of the main purposes of a namespace, but you can defeat it.

  br> In the scenario you paint, B::askForString() should work (whether or not B has
  br> a namespace).


  br> If (I am guessing) you want the version that would be gotten at the top level
  br> (the > prompt) whether or not B is in use, use

  br> get("askForString", pos=1)().



[Rd] How to override functions in namespaces?
Jeffrey J. Hallman