From murdoch.duncan at gmail.com  Mon Aug 30 18:00:59 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Mon, 30 Aug 2010 12:00:59 -0400
Subject: [Rd] introspective capabilities
In-Reply-To: <87iq2ws25s.fsf@cantab.net>
References: <87iq2ws25s.fsf@cantab.net>
Message-ID: <4C7BD5BB.7050501@gmail.com>

On 27/08/2010 7:52 AM, Christophe Rhodes wrote:
> Hi,
>
> Is there any way, from R code, to perform introspection as to where
> certain names acquired their values?  The specific functionality I'm
> looking for in this case is to be able to request my editor to view the
> definition corresponding to a name in its original source location
> (presuming for the moment that that location exists).  Other
> functionality that I'm looking for is to identify where in the current
> image a particular name is used -- "what functions use the value bound
> to a particular name?"
>
> The context for these questions, in case anyone is interested, is that I
> am usually a Common Lisp programmer, and my programming environment for
> that (SLIME) is what I'm used to.  R is sufficiently close to CL (the
> discovery of withCallingHandlers/withRestarts was a pleasant surprise)
> that I decided to experiment with implementing a SLIME backend for R --
> and enough of it seems to work that I'm motivated to make it more
> complete.  (The current state of the project is summarised at
> <http://common-lisp.net/~crhodes/swankr/>).
>
>   
There's the "keep.source" option to source() and the optional "srcfile" 
argument to parse() that tell R to keep this information.  If you 
haven't changed the default
getOption("keep.source") from TRUE, then source will default to keeping 
it, and you can find the original location of a function definition for 
function f by looking in attr(body(f), "srcref").  See ?srcref for the 
format; there aren't a lot of user-level utility functions for working 
with this.

For packages, the relevant option is "keep.source.pkgs" at the time the 
package is installed.

Duncan Murdoch



[Rd] introspective capabilities
Duncan Murdoch