Reading R's base code {was [R] xlims of barplot}

Martin Maechler maechler at
Fri Nov 14 14:57:31 CET 2003

>>>>> "Simon" == Simon Fear <Simon.Fear at>
>>>>>     on Thu, 13 Nov 2003 09:53:17 -0000 writes:

    Simon> I'd recommend you read the code for barplot (it's all
    Simon> in R; just type barplot.default at the prompt) then
    Simon> emulate the xlim calculation prior to starting your
    Simon> series of plots, calling each plot with the same
    Simon> xlim.

    Simon> Reading the base package coding is always VERY
    Simon> instructive.  Takes time, but it's worth it.

and Paul confirmed this was useful advice.

Just one general remark: Many users know that it is useful to
look at function definitions that way.  Less and less users
however seem to be aware that this is *NOT* the source code in a
strict sense.
One important difference is that the source code *does* have
comments that you'll never see for base package functions if you
just inspect their value.

While there is 
options(keep.source      = TRUE)  ## per default
options(keep.source.pkgs = FALSE) ## per default

these do not influence the base package code.
If you compile R from the source, then the base package source
is in the many     <R_SRC_HOME/src/library/base/R/*.R  files.  
Otherwise, you can still see the source __including__ comments
by inspecting the (about 1 MB large) file

> system.file("R","base")

which has all the definitions concatenated into one file.

For other packages than base, you might
1) consider setting
  > options(keep.source.pkgs = TRUE) 
  in your Rprofile {which will need more memory and time to load packages !!!},
2) or inspect the contents of, e.g.
  > system.file("R", "splines", package = "splines")
  for the splines package.
3) or (as I do) work with the real source in <sourcepackage>/R/*.R.

Martin Maechler <maechler at>
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

More information about the R-help mailing list