Quite often, it can be useful to identify which functions are being called by an R function. There are many ways to achieve this, such as for example massage the text representation of the function with regular expressions to basically find out what is just before round brackets.

The codetools package actually provides a much better way to do that, with the walkCode function.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .

#' Gets the functions called by fun
#' 
#' @param fun a function, or a character string
#' @return a named vector of occurences of each function, the values are 
#'         the number of times and the names are the functions
callees  function( fun ){

    ## dump the function and read it back in the expression e
    # TODO: is there a better way
    #       If I just use body( fun ), I don't get the arguments
    fun  match.fun( fun )
    con  textConnection( NULL, open = "w" )
    dump( "fun", con )
    e  parse( text = textConnectionValue(con) )[[1]]
    close( con )


    # initiate the functions vector whcih will be populated within
    # the code walker
    functions  NULL
    env  environment()

    # a code walker (see package codetools) that records function calls
    # this is inspired from the code walker used by showTree
    cw  makeCodeWalker (
        call = function (e, w) {
            if( is.null(e) || length(e) == 0 ) return()

            # add the current function to the list
            env[["functions"]] 
                    c( env[["functions"]], as.character(e[[1]]) )

            # process the list of expressions
            w$call.list( e[-1] , w )

        },
        leaf = function( e, w ){
            # deal with argument list of functions
            if( typeof( e ) == "pairlist" ){
                w$call.list( e, w )
            }
        },
        call.list = function( e, w ){
            for( a in as.list(e) ){
                if( !missing( a) ){
                    walkCode( a, w )
                }
            }
        },
        env = env # so that we can populate "functions"
    )

    # walk through the code with our code walker
    walkCode( e,  w = cw )

    # clean the output
    out  table( functions )
    out[ order( names(out) ) ]

}
Let's try this on the jitter function:
> require( codetools )
> source("http://romainfrancois.blog.free.fr/public/posts/callees/callees.R")
> jitter
function (x, factor = 1, amount = NULL)
{
    if (length(x) == 0L)
        return(x)
    if (!is.numeric(x))
        stop("'x' must be numeric")
    z 
> callees( jitter )
functions