Re: [R] accessing source code in R packages
Is there general documentation on a procedure to follow to: (a) Find what methods are available for a particular class of objects? (b) Find what classes of objects have methods defined for a partilar generic function? (c) Get the code that's actually used? For example, I recently needed to access numbers associated with an object of class lmer. Sundar suggested I use with 'getMethod(show, summary.lmer)'. However, this doesn't work with the example below. Thanks, spencer graves Francisco J. Zagmutt wrote: or getAnywhere() From: ronggui.wong [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch r-help@stat.math.ethz.ch Subject: Re: [R] accessing source code in R packages Date: Thu, 22 Sep 2005 10:03:45 +0800 R is open source. You can download the source code from CRAN. If you mean at the R prompt, usually you see the code for a function by typing the name of the function at the R prompt, without parentheses. `Usually' because some methods are delibrately `hidden' from users, and should only be accessed through their generics. There are still ways to get around that. sometimes,the getS3method is helpfull. library(MASS) princomp.default Error: object princomp.default not found getS3method(princomp,default) function (x, cor = FALSE, scores = TRUE, covmat = NULL, subset = rep(TRUE, nrow(as.matrix(x))), ...) { snip However, the code you get at the R prompt is not the _source_, as it does not contain any original comments. You need to go to the source I refer to above. Andy From: [EMAIL PROTECTED] Hi, I am new the R world and would like to know how can I access source codes of standard functions in R? Thanks, Ritesh. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html = = = = = = = = = = = = = = = = = = = = Ö Àñ£¡ ronggui.wong [EMAIL PROTECTED] 2005-09-22 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA [EMAIL PROTECTED] www.pdf.com http://www.pdf.com Tel: 408-938-4420 Fax: 408-280-7915 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] accessing source code in R packages
The original reply was deliberately (I guess) vague. (I've removed the history, as attributions had already been removed, in violation of copyright law. If you cite someone, you MUST credit the author.) Sometimes a little knowledge is a dangerous thing, and we have had a number of partially true answers. Spreading confusion between the S4 classes of the 'methods' package and the (sometimes called S3) classes of base R is also dangerous. The R documentation refers to S3 methods and classes unless otherwise stated (and in the methods package documentation). Please follow that lead. On Thu, 22 Sep 2005, Spencer Graves wrote: Is there general documentation on a procedure to follow to: (a) Find what methods are available for a particular class of objects? ?methods, unless you mean an S4 class. Be careful here: methods `for a particular class' are not all that might be dispatched, as methods for classes the object inherits from may also be used. Thus lm methods may be invoked for glm objects, and you may need to call methods() for all the classes the object inherits from. (b) Find what classes of objects have methods defined for a partilar generic function? ?methods, unless you mean S4 classes (and that help page leads you to the right place for those). (c) Get the code that's actually used? getAnywhere() on the asterisked results of (a) or (b). For a specific generic and a specific class, getS3method(). [There is a potential gap here as the bar method for class foo need not be called foo.bar(). So guessing the name may not work, but getS3method(foo, bar) will. AFAIK there are no live examples of this.] For example, I recently needed to access numbers associated with an object of class lmer. Sundar suggested I use with 'getMethod(show, summary.lmer)'. However, this doesn't work with the example below. (I think that was intended to refer to the default method for princomp, which is not an S4 generic in base R. methods(princomp) [1] princomp.default* princomp.formula* Non-visible functions are asterisked getAnywhere(princomp.default)# works getS3Method(princomp, default) # works showMethods(princomp) Function princomp: not a generic function ) show() is an S4 generic, not an S3 generic. ?methods points you to how to explore S4 generics. library(lme4) ... (and drink some coffee while you wait) methods(show) no methods were found Warning message: function 'show' appears not to be generic in: methods(show) showMethods(show) Function show: object = ANY object = traceable object = ObjectsWithPackage object = MethodDefinition object = MethodWithNext object = genericFunction object = classRepresentation object = ddenseMatrix object = Matrix object = lmer object = summary.lmer object = VarCorr object = sparseMatrix object = lmList selectMethod(show, summary.lmer) Method Definition: function (object) ... Here getMethod() will also work, but selectMethod() is more likely to find `the code that's actually used'. -- Brian D. Ripley, [EMAIL PROTECTED] 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, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] accessing source code in R packages
Dear Prof. Ripley: Thanks. This looks like a very useful summary. spencer graves Prof Brian Ripley wrote: The original reply was deliberately (I guess) vague. (I've removed the history, as attributions had already been removed, in violation of copyright law. If you cite someone, you MUST credit the author.) Sometimes a little knowledge is a dangerous thing, and we have had a number of partially true answers. Spreading confusion between the S4 classes of the 'methods' package and the (sometimes called S3) classes of base R is also dangerous. The R documentation refers to S3 methods and classes unless otherwise stated (and in the methods package documentation). Please follow that lead. On Thu, 22 Sep 2005, Spencer Graves wrote: Is there general documentation on a procedure to follow to: (a) Find what methods are available for a particular class of objects? ?methods, unless you mean an S4 class. Be careful here: methods `for a particular class' are not all that might be dispatched, as methods for classes the object inherits from may also be used. Thus lm methods may be invoked for glm objects, and you may need to call methods() for all the classes the object inherits from. (b) Find what classes of objects have methods defined for a partilar generic function? ?methods, unless you mean S4 classes (and that help page leads you to the right place for those). (c) Get the code that's actually used? getAnywhere() on the asterisked results of (a) or (b). For a specific generic and a specific class, getS3method(). [There is a potential gap here as the bar method for class foo need not be called foo.bar(). So guessing the name may not work, but getS3method(foo, bar) will. AFAIK there are no live examples of this.] For example, I recently needed to access numbers associated with an object of class lmer. Sundar suggested I use with 'getMethod(show, summary.lmer)'. However, this doesn't work with the example below. (I think that was intended to refer to the default method for princomp, which is not an S4 generic in base R. methods(princomp) [1] princomp.default* princomp.formula* Non-visible functions are asterisked getAnywhere(princomp.default)# works getS3Method(princomp, default) # works showMethods(princomp) Function princomp: not a generic function ) show() is an S4 generic, not an S3 generic. ?methods points you to how to explore S4 generics. library(lme4) ... (and drink some coffee while you wait) methods(show) no methods were found Warning message: function 'show' appears not to be generic in: methods(show) showMethods(show) Function show: object = ANY object = traceable object = ObjectsWithPackage object = MethodDefinition object = MethodWithNext object = genericFunction object = classRepresentation object = ddenseMatrix object = Matrix object = lmer object = summary.lmer object = VarCorr object = sparseMatrix object = lmList selectMethod(show, summary.lmer) Method Definition: function (object) ... Here getMethod() will also work, but selectMethod() is more likely to find `the code that's actually used'. -- Spencer Graves, PhD Senior Development Engineer PDF Solutions, Inc. 333 West San Carlos Street Suite 700 San Jose, CA 95110, USA [EMAIL PROTECTED] www.pdf.com http://www.pdf.com Tel: 408-938-4420 Fax: 408-280-7915 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] accessing source code in R packages
Hi, I am new the R world and would like to know how can I access source codes of standard functions in R? Thanks, Ritesh. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] accessing source code in R packages
R is open source. You can download the source code from CRAN. If you mean at the R prompt, usually you see the code for a function by typing the name of the function at the R prompt, without parentheses. `Usually' because some methods are delibrately `hidden' from users, and should only be accessed through their generics. There are still ways to get around that. However, the code you get at the R prompt is not the _source_, as it does not contain any original comments. You need to go to the source I refer to above. Andy From: [EMAIL PROTECTED] Hi, I am new the R world and would like to know how can I access source codes of standard functions in R? Thanks, Ritesh. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] accessing source code in R packages
R is open source. You can download the source code from CRAN. If you mean at the R prompt, usually you see the code for a function by typing the name of the function at the R prompt, without parentheses. `Usually' because some methods are delibrately `hidden' from users, and should only be accessed through their generics. There are still ways to get around that. sometimes,the getS3method is helpfull. library(MASS) princomp.default Error: object princomp.default not found getS3method(princomp,default) function (x, cor = FALSE, scores = TRUE, covmat = NULL, subset = rep(TRUE, nrow(as.matrix(x))), ...) { snip However, the code you get at the R prompt is not the _source_, as it does not contain any original comments. You need to go to the source I refer to above. Andy From: [EMAIL PROTECTED] Hi, I am new the R world and would like to know how can I access source codes of standard functions in R? Thanks, Ritesh. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html = = = = = = = = = = = = = = = = = = = = 致 礼! ronggui.wong [EMAIL PROTECTED] 2005-09-22 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] accessing source code in R packages
or getAnywhere() From: ronggui.wong [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch r-help@stat.math.ethz.ch Subject: Re: [R] accessing source code in R packages Date: Thu, 22 Sep 2005 10:03:45 +0800 R is open source. You can download the source code from CRAN. If you mean at the R prompt, usually you see the code for a function by typing the name of the function at the R prompt, without parentheses. `Usually' because some methods are delibrately `hidden' from users, and should only be accessed through their generics. There are still ways to get around that. sometimes,the getS3method is helpfull. library(MASS) princomp.default Error: object princomp.default not found getS3method(princomp,default) function (x, cor = FALSE, scores = TRUE, covmat = NULL, subset = rep(TRUE, nrow(as.matrix(x))), ...) { snip However, the code you get at the R prompt is not the _source_, as it does not contain any original comments. You need to go to the source I refer to above. Andy From: [EMAIL PROTECTED] Hi, I am new the R world and would like to know how can I access source codes of standard functions in R? Thanks, Ritesh. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html = = = = = = = = = = = = = = = = = = = = Ö Àñ£¡ ronggui.wong [EMAIL PROTECTED] 2005-09-22 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html