Source Code of R Method
There are different ways to view the source code of an R method or function. It will help to know how the function is working.
If you want to see the source code of the internal function (functions from base packages), just type the name of the function at R prompt such as;
One can still view its source code via the ::: function such as
or by using getAnywhere() function, such as
Note that the getAnywhere() function is useful as you don’t need to know from which package the function or method comes from.
Functions or Methods from S4 Class System
The S4 system is a newer method dispatch system and is an alternative to the S3 system. The package ‘Matrix’ is an example of S4 function.
> getMethod (“chol2inv”, “diagonalMatrix”)
Functions that Calls Unexported Functions
In the case of unexported functions such as ts.union, .cbindts and .makeNamesTs from the stats namespace, one can view source code of these unexported functions using ::: operator or getAnywhere() function, for example;
> stats::: .makeNamesTs