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?

user1871528
  • 1,655
  • 3
  • 27
  • 41
  • 1
    Looks like it's in the `stats` package, not `MASS`. Try `stats:::cooks.distance.lm`. – joran Mar 22 '13 at 20:14
  • 2
    `getAnywhere(cooks.distance.lm)` – Roland Mar 22 '13 at 20:18
  • 1
    This is a very similar question http://stackoverflow.com/questions/11173683/how-can-i-read-the-code-for-summary-for-a-data-frame and is part of the r-faq tag – Dason Mar 22 '13 at 22:01
  • Linked to wrong canonical question; should be **[How can I view the source code for a function?](http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function)** – smci Feb 01 '17 at 03:25

1 Answers1

3

Try this:

getAnywhere(cooks.distance.glm)

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

harkmug
  • 2,725
  • 22
  • 26