Question: Neither of these show the source code of `pnorm` function,

```
stats:::pnorm
getAnywhere(pnorm)  

```

How can i see the source code of `pnorm`?

```
sum
 (..., na.rm = FALSE)  .Primitive("sum")
.Primitive("sum")
function (..., na.rm = FALSE)  .Primitive("sum")
methods(sum)
no methods were found

```

and, how can I see source code of the `sum` function?

Answer: 
The R source code of `pnorm` is:

```
function (q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) 
.Call(C_pnorm, q, mean, sd, lower.tail, log.p)

```

So, technically speaking, typing "pnorm" *does* show you the source code. However, more usefully: The guts of `pnorm` are coded in C, so the advice in the previous question [view source code in R](https://stackoverflow.com/questions/3485228/view-source-code-in-r) is only peripherally useful (most of it concentrates on functions hidden in namespaces etc.).

Uwe Ligges's [article in R news, Accessing the Sources](http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf) (p. 43), is a good general reference. From that document:

> 
> When looking at R source code, sometimes calls
> to one of the following functions show up: `.C()`,
> `.Call()`, `.Fortran()`, `.External()`, or `.Internal()`
> and `.Primitive()`. These functions are calling entry points in compiled code such as shared objects,
> static libraries or dynamic link libraries. Therefore,
> it is necessary to look into the sources of the compiled code, if complete understanding of the code is
> required.
> ...
> The first step is to look up the
> entry point in file ‘$R HOME/src/main/names.c’, if
> the calling R function is either `.Primitive()` or
> `.Internal()`. **This is done in the following example for the code implementing the ‘simple’ R function
> `sum()`.**
> 
> 
> 

(Emphasis added because the precise function you asked about (`sum`) is covered in Ligges's article.)

Depending on how seriously you want to dig into the code, it may be worth downloading and
unpacking the source code as Ligges suggests (for example, then you can use command-line tools
such as `grep` to search through the source code). For more casual inspection, you can view
the sources online via the R [Subversion server](http://svn.r-project.org/R/trunk/src/nmath/pnorm.c) or [Winston Chang's github mirror](http://github.com/wch/r-source/blob/trunk/src/nmath/pnorm.c) (links here are specifically to `src/nmath/pnorm.c`). (Guessing the right place to look, `src/nmath/pnorm.c`, takes some familiarity with the structure of the R source code.)

`mean` and `sum` are both implemented in [summary.c](https://github.com/wch/r-source/blob/trunk/src/main/summary.c).
I know this post is more that 2 years old, but I thought this might be useful to some users browsing through this question.

I'm basically just copying my answer to [this other similar question](https://stackoverflow.com/questions/13279256/how-to-find-out-which-c-file-contains-the-c-functions-of-r-internals/29696967#29696967) so that it can maybe prove useful to some R users who want to explore the C source files.

1. First, with **pryr** you can use the `show_c_source` function which will search on GitHub the relevant piece of code in the C source files. Works for .Internal and .Primitive functions.

```
body(match.call)

# .Internal(match.call(definition, call, expand.dots))

pryr::show_c_source(.Internal(match.call(definition, call, expand.dots)))

```

Which takes you to [this page](https://github.com/search?q=SEXP%20attribute_hidden%20do_matchcall%20repo:wch/r-source&type=Code), showing that `unique.c` contains the function [do\_matchcall](https://github.com/wch/r-source/blob/ec8db8be924cf4ffd49438cbca38b876c7931863/src/main/unique.c#L1261).
2. I've put together this [tab delimited file](https://gist.github.com/dcomtois/261ff939d1a1b27525f1), building on the `names.c` file and using *find-in-files* to determine the location of the source code. There are some functions that have platform-specific files, and a handful of others for which there is more than one file with relevant source code. But for the rest the mapping is pretty well established, at least for the current version (3.1.2).