pretty.default
これは、とに対して非常にうまく機能するものですmodel.frame.default
。
print.func <- function(func, ...) {
str(as.list.func(func, ...), comp.str="")
}
as.list.func <- function(func, recurse.keywords = c("{", "if", "repeat", "while", "for", "switch")) {
as.list.func.recurse(body(func), recurse.keywords)
}
as.list.func.recurse <- function(x, recurse.keywords) {
x.list <- as.list(x)
top <- deparse(x.list[[1]])
if (length(x.list) > 1 && top %in% recurse.keywords) {
res <- lapply(x.list, as.list.func.recurse, recurse.keywords)
setNames(res, seq_along(res))
} else {
x
}
}
の結果pretty.default
:
> print.func(pretty.default)
List of 13
1 : symbol {
2 : language x <- x[is.finite(x <- as.numeric(x))]
3 :List of 3
..$ 1: symbol if
..$ 2: language length(x) == 0L
..$ 3: language return(x)
4 :List of 3
..$ 1: symbol if
..$ 2: language is.na(n <- as.integer(n[1L])) || n < 0L
..$ 3: language stop("invalid 'n' value")
5 :List of 3
..$ 1: symbol if
..$ 2: language !is.numeric(shrink.sml) || shrink.sml <= 0
..$ 3: language stop("'shrink.sml' must be numeric > 0")
6 :List of 3
..$ 1: symbol if
..$ 2: language (min.n <- as.integer(min.n)) < 0 || min.n > n
..$ 3: language stop("'min.n' must be non-negative integer <= n")
7 :List of 3
..$ 1: symbol if
..$ 2: language !is.numeric(high.u.bias) || high.u.bias < 0
..$ 3: language stop("'high.u.bias' must be non-negative numeric")
8 :List of 3
..$ 1: symbol if
..$ 2: language !is.numeric(u5.bias) || u5.bias < 0
..$ 3: language stop("'u5.bias' must be non-negative numeric")
9 :List of 3
..$ 1: symbol if
..$ 2: language (eps.correct <- as.integer(eps.correct)) < 0L || eps.correct > 2L
..$ 3: language stop("'eps.correct' must be 0, 1, or 2")
10: language z <- .C("R_pretty", l = as.double(min(x)), u = as.double(max(x)), n = n, min.n, shrink = as.double(shrink.sml), high.u.fact = as.double(c(high.u.bias, ...
11: language s <- seq.int(z$l, z$u, length.out = z$n + 1)
12:List of 3
..$ 1: symbol if
..$ 2: language !eps.correct && z$n
..$ 3:List of 3
.. ..$ 1: symbol {
.. ..$ 2: language delta <- diff(range(z$l, z$u))/z$n
.. ..$ 3:List of 3
.. .. ..$ 1: symbol if
.. .. ..$ 2: language any(small <- abs(s) < 1e-14 * delta)
.. .. ..$ 3: language s[small] <- 0
13: symbol s
の結果model.frame.default
:
> print.func(model.frame.default)
List of 29
1 : symbol {
2 : language possible_newdata <- !missing(data) && is.data.frame(data) && identical(deparse(substitute(data)), "newdata") && (nr <- nrow(data)) > 0
3 :List of 3
..$ 1: symbol if
..$ 2: language !missing(formula) && nargs() == 1 && is.list(formula) && !is.null(m <- formula$model)
..$ 3: language return(m)
4 :List of 3
..$ 1: symbol if
..$ 2: language !missing(formula) && nargs() == 1 && is.list(formula) && all(c("terms", "call") %in% names(formula))
..$ 3:List of 8
.. ..$ 1: symbol {
.. ..$ 2: language fcall <- formula$call
.. ..$ 3: language m <- match(c("formula", "data", "subset", "weights", "na.action"), names(fcall), 0)
.. ..$ 4: language fcall <- fcall[c(1, m)]
.. ..$ 5: language fcall[[1L]] <- as.name("model.frame")
.. ..$ 6: language env <- environment(formula$terms)
.. ..$ 7:List of 3
.. .. ..$ 1: symbol if
.. .. ..$ 2: language is.null(env)
.. .. ..$ 3: language env <- parent.frame()
.. ..$ 8: language return(eval(fcall, env, parent.frame()))
5 :List of 4
..$ 1: symbol if
..$ 2: language missing(formula)
..$ 3:List of 3
.. ..$ 1: symbol {
.. ..$ 2:List of 3
.. .. ..$ 1: symbol if
.. .. ..$ 2: language !missing(data) && inherits(data, "data.frame") && length(attr(data, "terms"))
.. .. ..$ 3: language return(data)
.. ..$ 3: language formula <- as.formula(data)
..$ 4:List of 3
.. ..$ 1: symbol if
.. ..$ 2: language missing(data) && inherits(formula, "data.frame")
.. ..$ 3:List of 4
.. .. ..$ 1: symbol {
.. .. ..$ 2:List of 3
.. .. .. ..$ 1: symbol if
.. .. .. ..$ 2: language length(attr(formula, "terms"))
.. .. .. ..$ 3: language return(formula)
.. .. ..$ 3: language data <- formula
.. .. ..$ 4: language formula <- as.formula(data)
6 : language formula <- as.formula(formula)
7 :List of 3
..$ 1: symbol if
..$ 2: language missing(na.action)
..$ 3:List of 2
.. ..$ 1: symbol {
.. ..$ 2:List of 4
.. .. ..$ 1: symbol if
.. .. ..$ 2: language !is.null(naa <- attr(data, "na.action")) & mode(naa) != "numeric"
.. .. ..$ 3: language na.action <- naa
.. .. ..$ 4:List of 3
.. .. .. ..$ 1: symbol if
.. .. .. ..$ 2: language !is.null(naa <- getOption("na.action"))
.. .. .. ..$ 3: language na.action <- naa
8 :List of 4
..$ 1: symbol if
..$ 2: language missing(data)
..$ 3: language data <- environment(formula)
..$ 4:List of 4
.. ..$ 1: symbol if
.. ..$ 2: language !is.data.frame(data) && !is.environment(data) && !is.null(attr(data, "class"))
.. ..$ 3: language data <- as.data.frame(data)
.. ..$ 4:List of 3
.. .. ..$ 1: symbol if
.. .. ..$ 2: language is.array(data)
.. .. ..$ 3: language stop("'data' must be a data.frame, not a matrix or an array")
9 :List of 3
..$ 1: symbol if
..$ 2: language !inherits(formula, "terms")
..$ 3: language formula <- terms(formula, data = data)
10: language env <- environment(formula)
11: language rownames <- .row_names_info(data, 0L)
12: language vars <- attr(formula, "variables")
13: language predvars <- attr(formula, "predvars")
14:List of 3
..$ 1: symbol if
..$ 2: language is.null(predvars)
..$ 3: language predvars <- vars
15: language varnames <- sapply(vars, function(x) paste(deparse(x, width.cutoff = 500), collapse = " "))[-1L]
16: language variables <- eval(predvars, data, env)
17: language resp <- attr(formula, "response")
18:List of 3
..$ 1: symbol if
..$ 2: language is.null(rownames) && resp > 0L
..$ 3:List of 3
.. ..$ 1: symbol {
.. ..$ 2: language lhs <- variables[[resp]]
.. ..$ 3: language rownames <- if (is.matrix(lhs)) rownames(lhs) else names(lhs)
19:List of 3
..$ 1: symbol if
..$ 2: language possible_newdata && length(variables)
..$ 3:List of 3
.. ..$ 1: symbol {
.. ..$ 2: language nr2 <- max(sapply(variables, NROW))
.. ..$ 3:List of 3
.. .. ..$ 1: symbol if
.. .. ..$ 2: language nr2 != nr
.. .. ..$ 3: language warning(gettextf("'newdata' had %d rows but variable(s) found have %d rows", nr, nr2), call. = FALSE)
20:List of 3
..$ 1: symbol if
..$ 2: language is.null(attr(formula, "predvars"))
..$ 3:List of 3
.. ..$ 1: symbol {
.. ..$ 2:List of 4
.. .. ..$ 1: symbol for
.. .. ..$ 2: symbol i
.. .. ..$ 3: language seq_along(varnames)
.. .. ..$ 4: language predvars[[i + 1]] <- makepredictcall(variables[[i]], vars[[i + 1]])
.. ..$ 3: language attr(formula, "predvars") <- predvars
21: language extras <- substitute(list(...))
22: language extranames <- names(extras[-1L])
23: language extras <- eval(extras, data, env)
24: language subset <- eval(substitute(subset), data, env)
25: language data <- .Internal(model.frame(formula, rownames, variables, varnames, extras, extranames, subset, na.action))
26:List of 4
..$ 1: symbol if
..$ 2: language length(xlev)
..$ 3:List of 2
.. ..$ 1: symbol {
.. ..$ 2:List of 4
.. .. ..$ 1: symbol for
.. .. ..$ 2: symbol nm
.. .. ..$ 3: language names(xlev)
.. .. ..$ 4:List of 3
.. .. .. ..$ 1: symbol if
.. .. .. ..$ 2: language !is.null(xl <- xlev[[nm]])
.. .. .. ..$ 3:List of 4
.. .. .. .. ..$ 1: symbol {
.. .. .. .. ..$ 2: language xi <- data[[nm]]
.. .. .. .. ..$ 3:List of 3
.. .. .. .. .. ..$ 1: symbol if
.. .. .. .. .. ..$ 2: language is.character(xi)
.. .. .. .. .. ..$ 3:List of 3
.. .. .. .. .. .. ..$ 1: symbol {
.. .. .. .. .. .. ..$ 2: language xi <- as.factor(xi)
.. .. .. .. .. .. ..$ 3: language warning(gettextf("character variable '%s' changed to a factor", nm), domain = NA)
.. .. .. .. ..$ 4:List of 4
.. .. .. .. .. ..$ 1: symbol if
.. .. .. .. .. ..$ 2: language !is.factor(xi) || is.null(nxl <- levels(xi))
.. .. .. .. .. ..$ 3: language warning(gettextf("variable '%s' is not a factor", nm), domain = NA)
.. .. .. .. .. ..$ 4:List of 5
.. .. .. .. .. .. ..$ 1: symbol {
.. .. .. .. .. .. ..$ 2: language xi <- xi[, drop = TRUE]
.. .. .. .. .. .. ..$ 3: language nxl <- levels(xi)
.. .. .. .. .. .. ..$ 4:List of 3
.. .. .. .. .. .. .. ..$ 1: symbol if
.. .. .. .. .. .. .. ..$ 2: language any(m <- is.na(match(nxl, xl)))
.. .. .. .. .. .. .. ..$ 3: language stop(gettextf("factor '%s' has new level(s) %s", nm, paste(nxl[m], collapse = ", ")), domain = NA)
.. .. .. .. .. .. ..$ 5: language data[[nm]] <- factor(xi, levels = xl, exclude = NULL)
..$ 4:List of 3
.. ..$ 1: symbol if
.. ..$ 2: symbol drop.unused.levels
.. ..$ 3:List of 2
.. .. ..$ 1: symbol {
.. .. ..$ 2:List of 4
.. .. .. ..$ 1: symbol for
.. .. .. ..$ 2: symbol nm
.. .. .. ..$ 3: language names(data)
.. .. .. ..$ 4:List of 3
.. .. .. .. ..$ 1: symbol {
.. .. .. .. ..$ 2: language x <- data[[nm]]
.. .. .. .. ..$ 3:List of 3
.. .. .. .. .. ..$ 1: symbol if
.. .. .. .. .. ..$ 2: language is.factor(x) && length(unique(x[!is.na(x)])) < length(levels(x))
.. .. .. .. .. ..$ 3: language data[[nm]] <- data[[nm]][, drop = TRUE]
27: language attr(formula, "dataClasses") <- sapply(data, .MFclass)
28: language attr(data, "terms") <- formula
29: symbol data