[R] R: function code

Federico Calboli f.calboli at imperial.ac.uk
Mon Apr 11 13:04:19 CEST 2005


On Mon, 2005-04-11 at 12:52 +0200, Clark Allan wrote:
> HI
> 
> sorry to be a nuisance to all!!!
> 
> how can i see the code of a particular function?
> 
> e.g. nnet just as an example

for some function just type the function name  and you get the code:

> ls
function (name, pos = -1, envir = as.environment(pos), all.names =
FALSE,
    pattern)
{
    if (!missing(name)) {
        nameValue <- try(name)
        if (identical(class(nameValue), "try-error")) {
            name <- substitute(name)
            if (!is.character(name))
                name <- deparse(name)
            pos <- name
        }
        else pos <- nameValue
    }
    all.names <- .Internal(ls(envir, all.names))
    if (!missing(pattern)) {
        if ((ll <- length(grep("[", pattern, fixed = TRUE))) >
            0 && ll != length(grep("]", pattern, fixed = TRUE))) {
            if (pattern == "[") {
                pattern <- "\\["
                warning(paste("replaced regular expression pattern",
                  sQuote("["), "by", sQuote("\\\\[")))
            }
            else if (length(grep("[^\\\\]\\[<-", pattern) > 0)) {
                pattern <- sub("\\[<-", "\\\\\\[<-", pattern)
                warning(paste("replaced", sQuote("[<-"), "by",
                  sQuote("\\\\[<-"), "in regular expression pattern"))
            }
        }
        grep(pattern, all.names, value = TRUE)
    }
    else all.names
}
<environment: namespace:base>


or check out the source code itself.


HTH

F
-- 
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St Mary's Campus
Norfolk Place, London W2 1PG

Tel  +44 (0)20 7594 1602     Fax (+44) 020 7594 3193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com




More information about the R-help mailing list