[R] How could I see the source code of functions in an R package?

arun smartpink111 at yahoo.com
Fri May 17 04:30:31 CEST 2013


HI,
methods(xyplot)
#[1] xyplot.formula* xyplot.ts*     
#
 #  Non-visible functions are asterisked
lattice:::xyplot.formula
function (x, data = NULL, allow.multiple = is.null(groups) || 
    outer, outer = !is.null(groups), auto.key = FALSE, aspect = "fill", 
    panel = lattice.getOption("panel.xyplot"), prepanel = NULL, 
    scales = list(), strip = TRUE, groups = NULL, xlab, xlim, 
    ylab, ylim, drop.unused.levels = lattice.getOption("drop.unused.levels"), 
    ..., lattice.options = NULL, default.scales = list(), default.prepanel = lattice.getOption("prepanel.default.xyplot"), 
    subscripts = !is.null(groups), subset = TRUE) 
--------------------------------------------------------
-------------------------------------------------------

           names(foo$legend) <- foo$legend[[1]]$args$space
    }
    class(foo) <- "trellis"
    foo
}


lattice:::xyplot.ts

A.K.


Hi, 

   How could I see the source code of functions in an R package? 
   If we type ?function_name , we will see documentations of the 
function_name. 
   If we type function_name, is what returns just the source code? Could we 
just save it in an .R file and modify as we want? However, it seems that 
sometimes the source code is hidden (or stored elsewhere?) As an example, 
could we see the source code of "xyplot" in the following example? 

   Thanks, 


> library(lattice) 
> xyplot 
function (x, data, ...) 
UseMethod("xyplot") 
<environment: namespace:lattice> 

> library(plm) 
Loading required package: bdsmatrix 

Attaching package: bdsmatrix 

The following object(s) are masked from package:base: 

    backsolve 

Loading required package: nlme 
Loading required package: Formula 
Loading required package: MASS 
Loading required package: sandwich 
Loading required package: zoo 

Attaching package: zoo 

The following object(s) are masked from package:base: 

    as.Date, as.Date.numeric 

> ?plm 
> plm 
function (formula, data, subset, na.action, effect = c("individual", 
    "time", "twoways"), model = c("within", "random", "ht", "between", 
    "pooling", "fd"), random.method = c("swar", "walhus", "amemiya", 
    "nerlove", "kinla"), inst.method = c("bvk", "baltagi"), index = NULL, 
    ...) 
{ 
    nframe <- length(sys.calls()) 
    is.a.list <- class(formula)[1] == "list" 
    if (is.a.list) { 
        plmlist <- match.call(expand.dots = FALSE) 
        plmlist[[1]] <- as.name("plm.list") 
        plmlist <- eval(plmlist, sys.frame(which = nframe)) 
        return(plmlist) 
    } 
    dots <- list(...) 
    effect <- match.arg(effect) 
    if (!any(is.na(model))) 
        model <- match.arg(model) 
    random.method <- match.arg(random.method) 
    inst.method <- match.arg(inst.method) 
    if (!is.na(model) && model == "ht") { 
        ht <- match.call(expand.dots = FALSE) 
        m <- match(c("formula", "data", "subset", "na.action", 
            "index"), names(ht), 0) 
        ht <- ht[c(1, m)] 
        ht[[1]] <- as.name("pht") 
        ht <- eval(ht, parent.frame()) 
        return(ht) 
    } 
    if (!is.null(dots$instruments)) { 
        as.Formula(formula, dots$instruments) 
        deprec.instruments <- paste("the use of the instruments argument is 
deprecated,", 
            "use two-part formulas instead") 
        warning(deprec.instruments) 
    } 
    if (inherits(data, "pdata.frame") && !is.null(index)) 
        warning("the index argument is ignored because data is a 
pdata.frame") 
    if (!inherits(data, "pdata.frame")) 
        data <- pdata.frame(data, index) 
    if (!inherits(formula, "pFormula")) 
        formula <- pFormula(formula) 
    if (length(formula)[2] == 2) 
        formula <- expand.formula(formula) 
    cl <- match.call() 
    mf <- match.call(expand.dots = FALSE) 
    m <- match(c("formula", "data", "subset", "na.action"), names(mf), 
        0) 
    mf <- mf[c(1, m)] 
    mf$drop.unused.levels <- TRUE 
    mf[[1]] <- as.name("model.frame") 
    mf$formula <- formula 
    mf$data <- data 
    data <- eval(mf, parent.frame()) 
    if (is.na(model)) { 
        attr(data, "formula") <- formula 
        return(data) 
    } 
    args <- list(model = model, effect = effect, random.method = 
random.method, 
        inst.method = inst.method) 
    result <- plm.fit(formula, data, model, effect, random.method, 
        inst.method) 
    result$call <- cl 
    result$args <- args 
    result 
} 
<environment: namespace:plm>



More information about the R-help mailing list