The R Project SVN R

Rev

Rev 3722 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed


R : Copyright 1998, The R Development Core Team
Version 0.63.0 Unstable (November 12, 1998)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type    "?license" or "?licence" for distribution details.

R is a collaborative project with many contributors.
Type    "?contributors" for a list.

Type    "demo()" for some demos, "help()" for on-line help, or
    "help.start()" for a HTML browser interface to help.

> 
> ls.base <- ls(pos=length(search()))#- something more elegant ?
> base.is.f <- sapply(ls.base, function(x) is.function(get(x)))
> bi <- ls.base[base.is.f]
> cat("\nNumber of base objects:\t\t", length(ls.base),
+     "\nNumber of builtin functions:\t", sum(base.is.f),
+     "\n\t starting with 'is.' :\t ",
+     length(is.bi <- bi[substring(bi,1,3) == "is."]), "\n")

Number of base objects:      1019 
Number of builtin functions:     998 
     starting with 'is.' :    37 
> ## 0.14 : 31
> ## 0.50 : 33
> ## 0.60 : 34
> ## 0.62 : 35
> 
> ## This can be useful:    Which of the  builtin functions are "primitive" ?
> is.primitive <- function(obj)  is.function(obj) && is.null(args(obj))
> 
> is.ALL <- function(obj, func.names = ls(pos=length(search())),
+          not.using = c("is.single", "is.na.data.frame",
+          "is.loaded", "is.empty.model"),
+          true.only = FALSE, debug = FALSE)
+ {
+     ## Purpose: show many 'attributes' of  R object __obj__
+     ## -------------------------------------------------------------------------
+     ## Arguments: obj: any R object
+     ## -------------------------------------------------------------------------
+     ## Author: Martin Maechler, Date:  6 Dec 96, 15:23
+ 
+     is.fn <- func.names[substring(func.names,1,3) == "is."]
+     use.fn <- is.fn[ is.na(match(is.fn, not.using))]
+ 
+     r <- if(true.only) character(0)
+     else structure(vector("list", length= length(use.fn)), names= use.fn)
+     for(f in use.fn) {
+   if(any(f == c("is.na", "is.finite"))) {
+       if(!is.list(obj) && !is.vector(obj) && !is.array(obj)) {
+       if(!true.only) r[[f]] <- NA
+       next
+       }
+   }
+   if(debug) cat(f,"")
+   fn <- get(f)
+   rr <- if(is.primitive(fn) || length(formals(fn))>0)  fn(obj) else fn()
+   if(!is.logical(rr)) cat("f=",f," --- rr  is NOT logical  = ",rr,"\n")
+   ##if(1!=length(rr))   cat("f=",f," --- rr NOT of length 1; = ",rr,"\n")
+   if(true.only && length(rr)==1 && rr) r <- c(r, f)
+   else if(!true.only) r[[f]] <- rr
+     }
+     if(debug)cat("\n")
+     if(is.list(r)) structure(r, class = "isList") else r
+ }
> 
> print.isList <- function(r, ...)
+ {
+     ## Purpose:    print METHOD  for  'isList' objects
+     ## -------------------------------------------------------------------------
+     ## Arguments:
+     ## -------------------------------------------------------------------------
+     ## Author: Martin Maechler, Date: 12 Mar 97, 15:07
+     ## >>>>> needs  cmp.logical <<
+     if(is.list(r)) {
+   nm <- format(names(r))
+   rr <- lapply(r,cmp.logical)
+   for(i in seq(along=r)) cat(nm[i],":",rr[[i]],"\n", ...)
+     } else NextMethod("print", ...)
+ }
> 
> cmp.logical <- function(log.v)
+ {
+     ## Purpose: compact printing of logicals
+     ## -------------------------------------------------------------------------
+     ## Arguments: log.v : logical vector
+     ## -------------------------------------------------------------------------
+     ## Author: Martin Maechler, Date: 13 Dec 96, 16:28
+     if(!is.logical(log.v)) {
+   warning("coercing argument 'log.v' to logical")
+   log.v <- as.logical(log.v)
+     }
+     structure(if(length(log.v) == 0) "()" else c(".","|")[ 1+ log.v],
+         class = "noquote")
+ }
> 
> 
> is.ALL(NULL)
Warning in fn(obj) : is.nan() applied to non-(list or vector)
is.R           : | 
is.array       : . 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : NA 
is.function    : . 
is.infinite    : () 
is.integer     : . 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : NA 
is.name        : . 
is.nan         : () 
is.null        : | 
is.numeric     : . 
is.object      : . 
is.ordered     : . 
is.pairlist    : | 
is.qr          : . 
is.real        : . 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : . 
> ##fails: is.ALL(NULL, not.using = c("is.single", "is.loaded"))
> is.ALL(NULL,   true.only = TRUE)
Warning in fn(obj) : is.nan() applied to non-(list or vector)
[1] "is.R"        "is.atomic"   "is.null"     "is.pairlist"
> is.ALL(list(), true.only = TRUE)
Warning in fn(obj) : is.na() applied to non-(list or vector)
Warning in fn(obj) : is.nan() applied to non-(list or vector)
[1] "is.R"      "is.list"   "is.vector"
> 
> is.ALL(1:5)
is.R           : | 
is.array       : . 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : | | | | | 
is.function    : . 
is.infinite    : . . . . . 
is.integer     : | 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . . . . . 
is.name        : . 
is.nan         : . . . . . 
is.null        : . 
is.numeric     : | 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : | 
> is.ALL(array(1:24, 2:4))
is.R           : | 
is.array       : | 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : | | | | | | | | | | | | | | | | | | | | | | | | 
is.function    : . 
is.infinite    : . . . . . . . . . . . . . . . . . . . . . . . . 
is.integer     : | 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . . . . . . . . . . . . . . . . . . . . . . . . 
is.name        : . 
is.nan         : . . . . . . . . . . . . . . . . . . . . . . . . 
is.null        : . 
is.numeric     : | 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : . 
> is.ALL(1 + 3)
is.R           : | 
is.array       : . 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : | 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : | 
is.function    : . 
is.infinite    : . 
is.integer     : . 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . 
is.name        : . 
is.nan         : . 
is.null        : . 
is.numeric     : | 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : | 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : | 
> e13 <- expression(1 + 3)
> is.ALL(e13)
is.R           : | 
is.array       : . 
is.atomic      : . 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : | 
is.factor      : . 
is.finite      : . 
is.function    : . 
is.infinite    : . 
is.integer     : . 
is.language    : | 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . 
is.name        : . 
is.nan         : . 
is.null        : . 
is.numeric     : . 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : | 
is.symbol      : . 
is.ts          : . 
is.vector      : | 
> ## fails (0.50-a) [is.loaded]
> ##   is.ALL(e13, not.using=c("is.single", "is.finite", "is.na"))
> is.ALL(y ~ x) #--> (0.49):  NA    for 'is.na' (& is.finite)
Warning in fn(obj) : is.nan() applied to non-(list or vector)
is.R           : | 
is.array       : . 
is.atomic      : . 
is.call        : | 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : NA 
is.function    : . 
is.infinite    : . . . 
is.integer     : . 
is.language    : | 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : NA 
is.name        : . 
is.nan         : . . . 
is.null        : . 
is.numeric     : . 
is.object      : | 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : | 
is.symbol      : . 
is.ts          : . 
is.vector      : . 
> 
> 
> is0 <- is.ALL(numeric(0))
> is0.ok <- 1 == (lis0 <- sapply(is0, length))
> is0[!is0.ok]
$is.finite
logical(0)

$is.infinite
logical(0)

$is.na
logical(0)

$is.nan
logical(0)

> is0 <- unlist(is0)
> is0
          is.R       is.array      is.atomic        is.call   is.character 
          TRUE          FALSE           TRUE          FALSE          FALSE 
    is.complex  is.data.frame      is.double is.environment  is.expression 
         FALSE          FALSE           TRUE          FALSE          FALSE 
     is.factor    is.function     is.integer    is.language        is.list 
         FALSE          FALSE          FALSE          FALSE          FALSE 
    is.logical      is.matrix        is.name        is.null     is.numeric 
         FALSE          FALSE          FALSE          FALSE           TRUE 
     is.object     is.ordered    is.pairlist          is.qr        is.real 
         FALSE          FALSE          FALSE          FALSE           TRUE 
  is.recursive      is.symbol          is.ts      is.vector 
         FALSE          FALSE          FALSE           TRUE 
> ispi <- unlist(is.ALL(pi))
> all(ispi[is0.ok] == is0)
[1] TRUE
> 
> is.ALL(numeric(0), true=TRUE)
[1] "is.R"       "is.atomic"  "is.double"  "is.numeric" "is.real"   
[6] "is.vector" 
> is.ALL(array(1,1:3), true=TRUE)
[1] "is.R"       "is.array"   "is.atomic"  "is.double"  "is.numeric"
[6] "is.real"   
> is.ALL(cbind(1:3), true=TRUE)
[1] "is.R"       "is.array"   "is.atomic"  "is.integer" "is.matrix" 
[6] "is.numeric"
> 
> is.ALL(structure(1:7, names = paste("a",1:7,sep="")))
is.R           : | 
is.array       : . 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : | | | | | | | 
is.function    : . 
is.infinite    : . . . . . . . 
is.integer     : | 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . . . . . . . 
is.name        : . 
is.nan         : . . . . . . . 
is.null        : . 
is.numeric     : | 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : | 
> is.ALL(structure(1:7, names = paste("a",1:7,sep="")), true.only = TRUE)
[1] "is.R"       "is.atomic"  "is.integer" "is.numeric" "is.vector" 
> 
> x <- 1:20 ; y <- 5 + 6*x + rnorm(20) ; lm.xy <- lm(y ~ x)
>                   #now (0.62) fails: is.ALL(lm.xy)
> is.ALL(structure(1:7, names = paste("a",1:7,sep="")))
is.R           : | 
is.array       : . 
is.atomic      : | 
is.call        : . 
is.character   : . 
is.complex     : . 
is.data.frame  : . 
is.double      : . 
is.environment : . 
is.expression  : . 
is.factor      : . 
is.finite      : | | | | | | | 
is.function    : . 
is.infinite    : . . . . . . . 
is.integer     : | 
is.language    : . 
is.list        : . 
is.logical     : . 
is.matrix      : . 
is.na          : . . . . . . . 
is.name        : . 
is.nan         : . . . . . . . 
is.null        : . 
is.numeric     : | 
is.object      : . 
is.ordered     : . 
is.pairlist    : . 
is.qr          : . 
is.real        : . 
is.recursive   : . 
is.symbol      : . 
is.ts          : . 
is.vector      : | 
> is.ALL(structure(1:7, names = paste("a",1:7,sep="")), true.only = TRUE)
[1] "is.R"       "is.atomic"  "is.integer" "is.numeric" "is.vector" 
>