R-alpha: YAI: mode(lm(.....) $ call) "language" vs. "call" // patch

Martin Maechler (maechler@stat.math.ethz.ch)
Mon, 3 Mar 97 12:28:41 +0100


Date: Mon, 3 Mar 97 12:28:41 +0100
Message-Id: <9703031128.AA00394@>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: R-testers@stat.math.ethz.ch
Subject: R-alpha: YAI: mode(lm(.....) $ call) "language" vs. "call" // patch

[YAI := Yet Another Incompatibility   S <-> R]
Excuse me, I just keep reporting.

Here is my example:

 .Random.seed <- c(629, 6137, 22167) # want reproducible output
 x <- sort(rnorm(40)); y <- 10 - 7*x + rnorm(40)/4;  lm.xy <- lm(y ~ x)

 mode(lm.xy $call) #-> "language"  (S has "call")
 is.call(lm.xy$call)#-> TRUE

## Yes, I use a function which  looks at the mode(..) of things...



Here is my PATCH:

--- mode	Mon Mar  3 12:07:34 1997
+++ /usr/local/R-alpha-0.16.1/src/library/base/funs/mode	Wed Dec 11 03:07:00 1996
@@ -1,14 +1,10 @@
 mode <- function(x) {
 	if (is.expression(x)) return("expression")
-	tx <- typeof(x)
-	if (tx == "real" ) return("numeric")
-	if (tx == "integer") return("numeric")
-	if (tx == "closure" || tx == "builtin" ) return("function")
-	if (tx == "language") {
-	 if(is.call(x)) return("call")
-	 if(is.name(x)) return("name")
-	}
-	tx
+	x <- typeof(x)
+	if (x == "real" ) return("numeric")
+	if (x == "integer") return("numeric")
+	if (x == "closure" || x == "builtin" ) return("function")
+	x
 }
 "mode<-" <- function(x, value) 
 {



BTW:  This is from  Splus 3.4  ``?mode'' (slightly re-formatted)

S>        These are generic functions, you may  create  methods  for
S>        these functions for specific classes of objects.
S> 
S>     storage.mode is relevant only when calling .Fortran or  .C
S>        with numeric data.  When mode(x) is "numeric", the data of
S>        x may be stored as integers,  or  as  single-precision  or
S>        double-precision  floating  point numbers: storage.mode(x)
S>        will be "integer", "single" or "double" correspondingly.
S> 
S>     The atomic modes  are:  
S>		"logical",  "numeric",  "complex", "character"  and  "null".
S>     The  other  modes are:
S> 	 "list", "function",
S> 	 "graphics", "expression", "comment.expression",
S> 	 "name",    "call",   "call(...)",
S>       "frame", "<-",  "<<-",  "missing",  "internal",  "repeat",
S>       "while",  "for",  "{",  "return",  "break",  "next", "if", "unknown".

-- Martin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-