From rmh@surfer.sbm.temple.edu  Mon Apr 23 04:09:22 2001
From: rmh@surfer.sbm.temple.edu (rmh@surfer.sbm.temple.edu)
Date: Mon, 23 Apr 2001 05:09:22 +0200 (MET DST)
Subject: [Rd] several bugs (PR#918)
Message-ID: <200104230309.FAA10241@pubhealth.ku.dk>

# Your mailer is set to "none" (default on Windows),
# hence we cannot send the bug report directly from R.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
#       r-bugs@r-project.org
#
######################################################



1. as.numeric behaves differently in R than in S and I think this
shows a bug in how S3 classes are implemented.

R:
> as.numeric
function (x, ...) 
UseMethod("as.double")
> as.double
function (x, ...) 
UseMethod("as.double")


S:
> as.numeric
function(x)
Internal(as.numeric(x), "As_vector", T, 4)
> as.double
function(x)
.Internal(as.double(x), "As_vector", T, 4)
>


As a consequence, a user function
  as.numeric.mv 
doesn't work as a method in R because it never gets called when
accessed as as.numeric(x).

> objects()
character(0)
> a <- list(NA)
> attr(a[[1]],"mv") <- "default"
> class(a) <- "mv"
> 
> a
[[1]]
[1] NA
attr(,"mv")
[1] "default"

attr(,"class")
[1] "mv"
> as.numeric(a)
[1] NA
> as.numeric.mv <- function(x, ...) {
+   print("we got here")
+  x
+ }
> 
> as.numeric(a)  ## the function as.numeric.mv was not called
[1] NA
> as.numeric.mv(a)
[1] "we got here"
[1] NA
> 



2. works in S-Plus 4.5, not in R.  What is the rationale for this difference?

a <- list(NULL)
attr(a[[1]],"mv") <- "default"

R gives the message
Error: attempt to set an attribute on NULL



3. Unimplemented features in rep, copyVector
> rep(list(1),1)
[[1]]
[1] 1

> rep(list(1,2,3),1)
Error in rep(list(1, 2, 3), 1) : Unimplemented feature in rep

> a <- matrix(list(1,2,3,4,5,6), 2, 3)

Error in matrix(list(1, 2, 3, 4, 5, 6), 2, 3) : 
	Unimplemented feature in copyVector


4. methods in S-Plus that aren't methods in R. 
a. %*% is a method in S-Plus 4.5 and is a primitive in R.
   Therefore a user function "%*%.mv" doesn't get called by  a %*% b



5. S-Plus 6 compatibility issues
a. S+4 and R use the function
     exists("function.name", mode="function")
   S+6 use the function
     existsFunction("function.name")

More generally, S-Plus 6 has the following functions
> objip("exists")
$splus:
[1] "exists"         "existsFunction" "file.exists"   

$main:
[1] "dbexists"       "dbexistsOld"    "dyn.exists"     "existsClass"
[5]  "existsClassDef" "existsDoc"     "existsMethod"  

Can you add these function names to R with sensible defaults until the S4
methods are fully in place?


b. S-Plus 6 uses the function oldClass
Can you add these functions and default definitions to R?
  oldClass <- function(...) class(...)   
  "oldClass<-" <- function(...) "class<-"(...)  


6. bug in "[" for lists

a <- list(1,2,3,4,5,6)
dim(a) <- c(2,3)
unlist(a)
> a[,1:2]
     [,1]   [,2]  
[1,] "NULL" "NULL"
[2,] "NULL" "NULL"

The same code in S+4 gives
> a[,1:2]
     [,1] [,2] 
[1,] 1    3   
[2,] 2    4   




--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = x86
 os = Win32
 system = x86, Win32
 status = 
 major = 1
 minor = 2.1
 year = 2001
 month = 01
 day = 15
 language = R

Windows 9x 4.0 (build 1212)  B

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] several bugs (PR#918)
rmh@surfer.sbm.temple.edu