Hello Pardon for the elementary question, I did try searching the archives with various terms, but to no avail. I am using R1.9.1 on a windows machine One of the great advantages of R (to me, anyway) is being able to see the code for a function , e.g. by typing sd one sees the code for getting a standard deviation. However, for many functions this only provides info. including UseMethod, eg. typing mosaicplot yields function (x, ...) UseMethod("mosaicplot") <environment: namespace:graphics> How can I see the code for such functions? Thanks in advance as always Peter Peter L. Flom, PhD Assistant Director, Statistics and Data Analysis Core Center for Drug Use and HIV Research National Development and Research Institutes 71 W. 23rd St www.peterflom.com New York, NY 10010 (212) 845-4485 (voice) (917) 438-0894 (fax)
Peter Flom wrote:> Hello > > Pardon for the elementary question, I did try searching the archives > with various terms, but to no avail. I am using R1.9.1 on a windows > machine > > One of the great advantages of R (to me, anyway) is being able to see > the code for a function , e.g. by typing sd one sees the code for > getting a standard deviation. > > However, for many functions this only provides info. including > UseMethod, eg. typing mosaicplot yields > > function (x, ...) > UseMethod("mosaicplot") > <environment: namespace:graphics> > > > How can I see the code for such functions?Any function whose body contains a call to UseMethod is an S3 generic function. To see all the possible methods for the function, use methods("mosaicplot") The default method will be called mosaicplot.default and that's probably the one you want to examine.
Peter Flom wrote:> Hello > > Pardon for the elementary question, I did try searching the archives > with various terms, but to no avail. I am using R1.9.1 on a windows > machine > > One of the great advantages of R (to me, anyway) is being able to see > the code for a function , e.g. by typing sd one sees the code for > getting a standard deviation. > > However, for many functions this only provides info. including > UseMethod, eg. typing mosaicplot yields > > function (x, ...) > UseMethod("mosaicplot") > <environment: namespace:graphics> > > > How can I see the code for such functions? > >Peter, UseMethod implies that mosaicplot is a generic method. You can see which classes allow mosaicplot by using ?methods: > methods("mosaicplot") [1] mosaicplot.default* mosaicplot.formula* Non-visible functions are asterisked > Now that last statement tells me that mosaicplot.default and mosaicplot.formula are not exported objects in the graphics namespace. To actually see the code for say the default mosaicplot, use ?getAnywhere (or ?getS3method): > getAnywhere("mosaicplot.default") A single object matching 'mosaicplot.default' was found It was found in the following places registered S3 method for mosaicplot from namespace graphics namespace:graphics with value function (x, main = deparse(substitute(x)), sub = NULL, xlab = NULL, ylab = NULL, sort = NULL, off = NULL, dir = NULL, color = FALSE, shade = FALSE, margin = NULL, cex.axis = 0.66, las = par("las"), type = c("pearson", "deviance", "FT"), ...) { <snip> } You can learn about object-oriented programming in R from several places, but "Writing R Extensions" might be a good place to start. --sundar