添加以下几个问题:
- What other information is needed to fully describe an entity?
除<条码>、<条码>、<>条码>、<>条码>、<条码>、<条码>、<条码>、<条码>、<条码>、>等外,还应注意到<条码>各项指示/代码>。
is(1)
[1] "numeric" "vector"
虽然有用,但它也不能令人满意。 举例来说,<代码>1不止是这样;它也是原子、定型和双重的。 下述功能应显示所有物体均符合<代码>is.(......)功能:
what.is <- function(x, show.all=FALSE) {
# set the warn option to -1 to temporarily ignore warnings
op <- options("warn")
options(warn = -1)
on.exit(options(op))
list.fun <- grep(methods(is), pattern = "<-", invert = TRUE, value = TRUE)
result <- data.frame(test=character(), value=character(),
warning=character(), stringsAsFactors = FALSE)
# loop over all "is.(...)" functions and store the results
for(fun in list.fun) {
res <- try(eval(call(fun,x)),silent=TRUE)
if(class(res)=="try-error") {
next() # ignore tests that yield an error
} else if (length(res)>1) {
warn <- "*Applies only to the first element of the provided object"
value <- paste(res,"*",sep="")
} else {
warn <- ""
value <- res
}
result[nrow(result)+1,] <- list(fun, value, warn)
}
# sort the results
result <- result[order(result$value,decreasing = TRUE),]
rownames(result) <- NULL
if(show.all)
return(result)
else
return(result[which(result$value=="TRUE"),])
}
因此,我们现在有了更完整的情况:
> what.is(1)
test value warning
1 is.atomic TRUE
2 is.double TRUE
3 is.finite TRUE
4 is.numeric TRUE
5 is.vector TRUE
> what.is(CO2)
test value warning
1 is.data.frame TRUE
2 is.list TRUE
3 is.object TRUE
4 is.recursive TRUE
您还获得更多关于以下论点的信息:show.all=TRUE
。 我不在此举任何例子,因为结果有50条线以上。
最后,这意味着作为信息的补充来源,而不是取代先前提到的任何其他职能。
http://www.ohchr.org。
为了按照“Erdogan”的意见列入更多的“is”职能,你可以将此范围添加到以下职能中:
# right after
# list.fun <- grep(methods(is), pattern = "<-", invert = TRUE, value = TRUE)
list.fun.2 <- character()
packs <- c( base , utils , methods ) # include more packages if needed
for (pkg in packs) {
library(pkg, character.only = TRUE)
objects <- grep("^is.+\w$", ls(envir = as.environment(paste( package , pkg, sep = : ))),
value = TRUE)
objects <- grep("<-", objects, invert = TRUE, value = TRUE)
if (length(objects) > 0)
list.fun.2 <- append(list.fun.2, objects[sapply(objects, function(x) class(eval(parse(text = x))) == "function")])
}
list.fun <- union(list.fun.1, list.fun.2)
# ...and continue with the rest
result <- data.frame(test=character(), value=character(),
warning=character(), stringsAsFactors = FALSE)
# and so on...