[R] Getting the source file's name where the custom function is written

Martin Maechler maechler at stat.math.ethz.ch
Thu Mar 10 10:20:56 CET 2011


>>>>> Duncan Murdoch <murdoch.duncan at gmail.com>
>>>>>     on Wed, 09 Mar 2011 07:05:33 -0500 writes:

    > On 11-03-09 4:41 AM, Ivan Calandra wrote:
    >> Hi,
    >> 
    >> There might be better solution, but I think this works
    >> (got it by searching "source function" with
    >> RSiteSearch()): attr(body(myPrint), "srcfile")

    > That's the right way, but it only works if srcrefs (debug
    > information) is kept.  By default source() keeps it in
    > interactive sessions, but packages don't.

    > See ?options, in particular keep.source and
    > keep.source.pkgs for details.

Exactly.   I'd just like point to the note in 'keep.source.pkgs'
there:
          > Note this does not apply to packages using lazy-loading.
          > Whether they have kept source is determined when they are
          > installed (and is almost certainly false).

and "almost certainly"  is really correct and applies to 
"almost all" users, where my Bayesian a priori estimate of that
proportion would be '> 0.9999'. 

Martin Maechler

    > Duncan Murdoch

    >> Here is the original answer:
    >> http://finzi.psych.upenn.edu/Rhelp10/2010-February/227805.html
    >> 
    >> HTH, Ivan
    >> 
    >> Le 3/9/2011 10:19, raymondowf a écrit :
    >>> Dear R experts, I've written some functions in a few source
    >>> files (such as main.R, control.R ...).  After loading them
    >>> into R, how do I retrieve which functions are loaded from
    >>> which source file?
    >>> 
    >>> For example: main.R has functions: myPrint(), myScan()
    >>> control.R has functions: setPrinter(), setData()
    >>> 
    >>> After loading the sources (main.R and control.R) into R, I
    >>> would want to know that myPrint() and myScan are from main.R
    >>> while the rest from control.R
    >>> 
    >>> Many thanks!!!



More information about the R-help mailing list