源代码查看R
对funciton说why时,这三个方法基本够用
edit ;getAnywhere;methods
- edit
edit(getAnywhere)
# result:
function (x)
{
if (tryCatch(!is.character(x), error = function(e) TRUE))
x <- as.character(substitute(x))
objs <- list()
where <- character()
visible <- logical()
if (length(pos <- find(x, numeric = TRUE))) {
objs <- lapply(pos, function(pos, x) get(x, pos = pos),
x = x)
where <- names(pos)
visible <- rep.int(TRUE, length(pos))
}
if (length(grep(".", x, fixed = TRUE))) {
np <- length(parts <- strsplit(x, ".", fixed = TRUE)[[1L]])
for (i in 2:np) {
gen <- paste(parts[1L:(i - 1)], collapse = ".")
cl <- paste(parts[i:np], collapse = ".")
if (gen == "" || cl == "")
ne