3

I'm trying to view a source code. For example for cook.distance(). This is what I have tried

cooks.distance
function (model, ...) 
UseMethod("cooks.distance")
<bytecode: 0x3f25b5c>
<environment: namespace:stats>

then i tried:

 debug(cooks.distance)

and got nothing. Then I tried:

 methods(cooks.distance)
 [1] cooks.distance.glm* cooks.distance.lm* 

 Non-visible functions are asterisked

then I tried:

 lm:::cooks.distance.default
 Error in loadNamespace(name) : there is no package called ‘lm’

someone told me lm was in the MASS package so I tried the following:

 MASS:::cooks.distance.default
 Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : 
 object 'cooks.distance.default' not found

how can I view the source code? I tried to look in the source code but could not locate the function?

4
  • 1
    Looks like it's in the stats package, not MASS. Try stats:::cooks.distance.lm. Commented Mar 22, 2013 at 20:14
  • 2
    getAnywhere(cooks.distance.lm) Commented Mar 22, 2013 at 20:18
  • 1
    This is a very similar question stackoverflow.com/questions/11173683/… and is part of the r-faq tag Commented Mar 22, 2013 at 22:01
  • Linked to wrong canonical question; should be How can I view the source code for a function? Commented Feb 1, 2017 at 3:25

1 Answer 1

3

Try this:

getAnywhere(cooks.distance.glm)

From here: http://cran.r-project.org/doc/manuals/R-intro.html#Object-orientation

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.