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

Duncan Murdoch murdoch.duncan at gmail.com
Wed Mar 9 13:05:33 CET 2011


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.

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!!!
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Getting-the-source-file-s-name-where-the-custom-function-is-written-tp3343135p3343135.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list