The R Project SVN R

Rev

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


R : Copyright 2000, The R Development Core Team
Version 0.99.0 Under development (unstable) (January 29, 2000)

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.
Type    "q()" to quit R.

> #### Which functions in R  are    .Primitive()  / which should be ?
> #### ------------------------------------------------------------
> #### M.Maechler, May, 1998.
> ####
> #### ==> ../doc/manual/primitive-funs.tex
> ####   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> bpos <- match("package:base",search())
> nn <- ls(pos=bpos)
> length(nn) # 844 [R 0.62.0, March 25, 1998;  1067 R 0.64.0 March 1999]
[1] 1155
> 
> is.primitive <- function (obj) is.function(obj) && is.null(args(obj))
> is.special <- function(obj) typeof(obj) == "special"
> 
> Primf <- nn[sapply(nn, function(N) is.primitive(get(N, pos=bpos)))]
> length(Primf) ## 195  R 0.62.0, March 25, 1998
[1] 136
> ## 132    R 0.62.2+
> Real.primitives <-
+     list(
+    specials = c("{", "(", "if", "for", "while", "repeat", "break", "next",
+    "return", "function",
+    "on.exit" ## on.exit(expression, add=F) has two arguments in S-plus !
+    ),
+    language = c("$", "$<-", "<-", "<<-", "[", "[<-", "[[", "[[<-"),
+    arith = c("%%", "%*%", "%/%","*", "+", "-", "/", "^"),
+    logic = c("!",  "&", "&&",  "|", "||",
+    "<", "<=", "==", ">", ">=", "!="),
+    arithF =
+    c("sign", "abs",
+      "floor", "ceiling", "trunc",
+      "sqrt",
+      "exp",   ## NOT: "log",
+      "cos",     "sin",  "tan",
+      "acos",   "asin", "atan", ## Not:  atan2
+      "cosh",   "sinh", "tanh",
+      "acosh","asinh","atanh",
+      "cumsum","cumprod",
+      "cummax", "cummin"
+      ),
+    arithC = c("Arg", "Conj", "Im", "Mod", "Re"),
+ 
+    programming =
+    c("nargs", "missing", # actually args(.) could be as formal(.)
+      "interactive",
+      ".Primitive", ".Internal", ".External", ".Call",
+      ".C", ".Fortran", "symbol.C", "symbol.For",
+      "globalenv", "pos.to.env", "unclass",
+ 
+      ##maybe ? "gc", "gcinfo",
+      ##
+      "debug", "undebug", "trace", "untrace",
+      "browser",  "proc.time", #"traceback",
+      ),
+ 
+    language2= c(":", "~", "c", "list", #nomore (Sep.9,1998): "unlist",
+    ".Alias",
+    "call", "as.call", "expression", "substitute",
+    "UseMethod", ## ? really ?
+    "invisible",
+    ),
+ 
+    language3=
+    c("environment<-",
+      "length",    "length<-",
+      "class", "class<-",
+      ## "attr", not anymore [Summer '98]
+      "attr<-",
+      "attributes",    "attributes<-",
+      "dim",       "dim<-",
+      "dimnames",  "dimnames<-",
+      ## MM:   "comment", "comment<-",
+      ## New data.frame code
+      ##      "levels", "levels<-",
+      ##      "codes",  "codes<-",
+      ##      "[.data.frame",  "[<-.data.frame",
+      ##      "[[.data.frame", "[[<-.data.frame"
+      ),
+    )
> real.primitives <- unlist(Real.primitives)
> ##names(real.primitives) <- rep("",length(real.primitives))
> 
> !any(duplicated(real.primitives)) # TRUE
[1] TRUE
> all(real.primitives %in% Primf)     # TRUE
[1] TRUE
> 
> "%w/o%" <- function(a,b)  a[! a %in% b]    ## a without b
> 
> prim.f <- Primf %w/o% real.primitives
> ## see below: contains the is.xxxx(.) funtions
> length(prim.f) == length(Primf) - length(real.primitives)# TRUE
[1] TRUE
> 
> Specf <- Primf[iPsp <- sapply(Primf, function(N) is.special(get(N, pos=bpos)))]
> length(Specf) ## 36 [ R 0.63 ]
[1] 36
> Specf
 [1] "$"           "$<-"         "&&"          ".Internal"   "<-"         
 [6] "<<-"         "UseMethod"   "["           "[<-"         "[["         
[11] "[[<-"        "attr<-"      "break"       "browser"     "c"          
[16] "call"        "dim"         "dim<-"       "dimnames"    "dimnames<-" 
[21] "expression"  "for"         "function"    "if"          "interactive"
[26] "missing"     "nargs"       "next"        "on.exit"     "repeat"     
[31] "return"      "substitute"  "while"       "{"           "||"         
[36] "~"          
> ## the non-"special" ones:
> all("builtin" == sapply(Primf[!iPsp], function(N) typeof(get(N, pos=bpos))))
[1] TRUE
> 
> 
> ncpf <- nchar(prim.f)
> table(ncpf)
ncpf
 5  6  7  8  9 10 11 12 13 14 
 1  1  5  1  7  4  4  2  1  1 
> prim.f[ncpf <= 6]#  only is.na, is.nan
[1] "is.na"  "is.nan"
> 
> ( prim.isf <- prim.f[p.isis <- substr(prim.f,1,2) == "is"] )
 [1] "is.array"       "is.atomic"      "is.call"        "is.character"  
 [5] "is.complex"     "is.double"      "is.environment" "is.expression" 
 [9] "is.finite"      "is.function"    "is.infinite"    "is.integer"    
[13] "is.language"    "is.list"        "is.loaded"      "is.logical"    
[17] "is.matrix"      "is.na"          "is.name"        "is.nan"        
[21] "is.null"        "is.numeric"     "is.object"      "is.pairlist"   
[25] "is.real"        "is.recursive"   "is.single"     
> 
> length(prim.f2 <- prim.f[! p.isis]) # down to 87   [R 0.62.0, March 25, 1998]
[1] 0
>                   # 61  [March 27]
>                   # 43  [April 17];  38 [April 22]
> ##-> 0    [May 1, 1998]
> 
> prim.f2 # character(0) --- none left! --
character(0)
> 
> for(n in prim.f2)
+     cat(n," <- function(*) .Internal(",n,"(*))\n", sep="")
>