I know I should probably RTFM for this question, but could someone tell me if R supports the idea of "viewing source" on any particular function you want to use? If I want to "view source" on the rpois() function, for example, can I do somethink like: source(rpois) To see how the function is implemented? Regards, Paul Meagher Datavore Productions 50 Wood Grove Drive Truro, Nova Scotia B2N-6Y4 1.902.895.9671 www.datavore.com
Paul Meagher wrote:> If I want to "view source" on the rpois() function, for example, can I do > somethink like: > > source(rpois) > > To see how the function is implemented? >You mean you've never typed 'ls' instead of 'ls()' and discovered this for yourself? I still do it all the time, and I've been using S/R for ten+ years :) Ah, maybe you're not a Unix person ('ls' is the command to list files). Just type a function name to see the source, or to see how it disappears into R's internal code. You can also do print(rpois), but you'll see for rpois it disappears into internal code: function (n, lambda) .Internal(rpois(n, lambda)) <environment: namespace:base> - now you need to get the full source code for R and look into C code. Baz
Most of the time you just use rpois or, to use a pager, page(rpois) For some functions the function is hidden from the end user, and for those (indeed, for any object the system can find) you can use getAnywhere("foo.bar") In your example, it will not be too revealing:> rpoisfunction (n, lambda) .Internal(rpois(n, lambda)) .... On Tue, 26 Aug 2003, Paul Meagher wrote:> I know I should probably RTFM for this question, but could someone tell me > if R supports the idea of "viewing source" on any particular function you > want to use? > > If I want to "view source" on the rpois() function, for example, can I do > somethink like: > > source(rpois) > > To see how the function is implemented?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
> If I want to "view source" on the rpois() function, for example, can I do > somethink like: > > source(rpois) > > To see how the function is implemented?Just type the name of the function
On Tue, 26 Aug 2003, Paul Meagher wrote:> I know I should probably RTFM for this question, but could someone tell me > if R supports the idea of "viewing source" on any particular function you > want to use? > > If I want to "view source" on the rpois() function, for example, can I do > somethink like: > > source(rpois) > > To see how the function is implemented?It's even simpler in most cases, but you have picked an especially complicated example Just type the name of the function to see the R code > rpois function (n, lambda) .Internal(rpois(n, lambda)) But in this case it tells you that rpois is implemented in C code :( By convention, it is likely to be a function called do_rpois, however in this case we have an exception to the convention. You can look in src/main.names.c for the name of the C function. abacus% fgrep rpois names.c {"rpois", do_random1, 3, 11, 2, {PP_FUNCALL, PREC_FN,0}}, so the function do_random1 is actually involved. If you grep for that, you are directed to src/main/random.c and you will eventually find that the underlying code is in src/nmath/rpois.c and is commented with a reference to the ACM Transactions on Mathematical Software. -thomas