In S-Plus, I can look at the structure of a function (for example, hist) simply by entering hist <RETURN> however, if I do this in R, I get the response function (x, ...) UseMethod("hist") <environment: namespace:graphics> How can I inspect the structure of a function in R? ------------------------------- Richard Dybowski 143 Village Way Pinner HA5 5AA, UK Tel: 07976 250092
Richard Dybowski wrote:> In S-Plus, I can look at the structure of a function (for example, hist) > simply by entering > hist <RETURN> > however, if I do this in R, I get the response > function (x, ...) > UseMethod("hist") > <environment: namespace:graphics> > How can I inspect the structure of a function in R?Well, if hist() would be a an S3 generic with methods in S-PLUS as well, it would look quite similar like in R... Type methods(hist) to see which methods do exists, in particular you want to get hist.default, I guess. Uwe Ligges> ------------------------------- > Richard Dybowski > 143 Village Way > Pinner HA5 5AA, UK > Tel: 07976 250092 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > R-project.org/posting-guide.html
Richard, There are usually several methods available - depending on the class of the object you apply 'hist' on. In this case two are 'non-visible' ######> methods(hist)[1] hist.Date* hist.default hist.POSIXt* Non-visible functions are asterisked ###### Probably you are interested in hist.default ######> hist.defaultfunction (x, breaks = "Sturges", freq = NULL, probability = !freq, include.lowest = TRUE, right = TRUE, density = NULL, angle = 45, col = NULL, border = NULL, main = paste ... snip ... } else r } <environment: namespace:graphics> ###### Fredrik Lundgren ----- Original Message ----- From: "Richard Dybowski" <richard at inferspace.com> To: <r-help at stat.math.ethz.ch> Sent: Monday, January 03, 2005 11:50 AM Subject: [R] Inspecting R functions> In S-Plus, I can look at the structure of a function (for example, > hist) simply by entering > hist <RETURN> > however, if I do this in R, I get the response > function (x, ...) > UseMethod("hist") > <environment: namespace:graphics> > How can I inspect the structure of a function in R? > > ------------------------------- > Richard Dybowski > 143 Village Way > Pinner HA5 5AA, UK > Tel: 07976 250092 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > R-project.org/posting-guide.html >
On Mon, 3 Jan 2005, Richard Dybowski wrote:> In S-Plus, I can look at the structure of a function (for example, hist) > simply by entering > hist <RETURN> > however, if I do this in R, I get the response > function (x, ...) > UseMethod("hist") > <environment: namespace:graphics> > How can I inspect the structure of a function in R?I think you mean `read the code', as S-PLUS has inspect() that does something different, and you don't want the internal structure, do you? You have! hist() in R is generic, and it is not in S-PLUS. See also ?methods and ?getAnywhere, -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, 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
On Mon, 03 Jan 2005 10:50:22 +0000, Richard Dybowski <richard at inferspace.com> wrote:>In S-Plus, I can look at the structure of a function (for example, hist) >simply by entering > hist <RETURN> >however, if I do this in R, I get the response > function (x, ...) > UseMethod("hist") > <environment: namespace:graphics> >How can I inspect the structure of a function in R?It's the same as in S-PLUS, what you saw *is* the structure of hist in R, i.e. it is an S3 generic. To see the implementation for a particular class, you need to say which method you want to look at, and then use getS3method to see it. For example, getS3method('hist', 'default') shows the default method. Duncan