[Rd] "Incompatible methods" for overloaded operator

2012-06-14 Thread Winston Chang
I'm trying to overload an operator, and I'm running into a strange problem.
It happens when I install and load the package, but not when I simply
source() the code.

I'm defining + for two classes. The R code looks like this:
#' @export
#' @method "+" a
`+.a` <- function (x1, x2) {
message("Running custom + function")
}

#' @export
#' @method "+" b
`+.b` <- `+.a`

In some cases I do a+b, and in other cases, I do b+b. I'm told that the +.a
and +.b functions must be identical to avoid the error about "Incompatible
methods". (In the actual code, the overloaded + function checks the classes
of x1 and x2, and then sends them off to other functions.)

This is the NAMESPACE file:
S3method("+",a)
S3method("+",b)

I've put the code up at https://github.com/wch/badadd.



If I just cut and paste the function definitions to my R session, it works
fine:
x + y
# Running + function
# NULL


However, if I install and load the package, it gives a warning about
incompatible methods, and then seems to fall back to the arithmetic +
operator:
library(badadd)
x + y
# [1] 3
# attr(,"class")
# [1] "a"
# Warning message:
# Incompatible methods ("+.a", "+.b") for "+"


Is this expected behavior? And if so, is there a workaround?
-Winston

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] x11 icon and class

2012-06-14 Thread Philip Johnson


On 06/12/2012 03:50 PM, Davor Cubranic wrote:

On 2012-06-07, at 12:05 PM, Philip Johnson wrote:


The X11 device driver does not provide the X window manager with an icon 
(_NET_WM_ICON) or, under some circumstances, with a class (WM_CLASS). This 
hinders usability under the new stable version of Ubuntu, which has a (new) 
user interface centered around icons.

[...]
  2) WM_CLASS (for reasons unclear to me, previously WM_CLASS was only set 
#ifndef USE_Xt)


A few comments in the bug database give a hint why this is conditional 
(http://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14588):

(1) "resources are only handled in the Xt case" (comment #1)
(2) "Still no explanation as to why Xt is not used, and this should be conditional 
on that case." (comment #3)


True, however, as far as I could tell, these comments do not apply to 
the current code for the following reasons:


(1) ./configure --with-x requires that Xt be present
(2) devX11.c includes a line "#define USE_Xt 1" -- implying that Xt is 
*always* used if compiling for X11
(3) Xt* functions are only used in a single small block in the code, and 
no windows are created in that code -- and thus no X resources are EVER 
set.  I *think* that the only purpose of this code is to test whether 
the window manager allows the user to specify window position and size. 
 But these fields in XSizeHints are noted in the current man pages as 
"obsolete and left solely for compatibility reasons".
(4) deleting all Xt code makes no discernable difference in the device 
driver behaviour on my (admittedly modern) linux distribution.




Now that GUI libraries typically don't rely on Xt any more (e.g., Gtk), but 
WM_CLASS (and possibly other resources) are still used by window managers, it 
arguably makes sense for the X11 driver to always set this property.


This is my argument in a nutshell.  I understand there is a general 
reluctance to delete old code because it might still be used on an old 
system somewhere, but I think my proposed change would only be adding 
functionality, not removing it.


After I sent the patch, I discovered that the integration with the new 
Ubuntu interface works even better if WM_CLASS matches the name of the 
executable -- i.e. if the class were "R" rather than "R_x11".  I don't 
want to spam this list, but I am happy to send a revised patch if asked.


Regards,
Philip

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] 7 arguments passed to .Internal(identical) which requires 6

2012-06-14 Thread Matthew Dowle
Matthew Dowle  mdowle.plus.com> writes:
> 
> Will check R-Forge again when it catches up. Thanks.
> Matthew
> 

Just to confirm, R-Forge has today caught up and is now using R r59554 which 
includes the fix for the problem in this thread. Its binary build of data.table 
is now installing fine on R 2.15.0 release, which it wasn't doing before.

Many thanks,
Matthew

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Reference class inheritance using matrix/array class

2012-06-14 Thread EJ Nikelski
Hi,

  I'm investigating converting some S4 classes to reference classes
and have a question about inheritance. The primary data structure for
the original S4 class is a 3-d array. Using the "contains" parameter
when defining the class  permits me to inherit all of the
array-related methods. Of particular utility for me is the ability to
access the array via [] indexing. It all works quite well.

 I'm interested in converting to a Ref class since R's copy-on-change
semantics may be causing a fair bit of overhead whenever an element
within the array is changed (and the arrays can be quite large). I
also would like the inherited indexing methods to continue to work.
Looking at ?setRefClass, I note under the contains parameter:

" ... If a superclass is also a reference class, the fields and
class-based methods will be inherited."

This statement *suggests* that inheritance of methods only works for
other Ref classes, but is not explicit WRT other base classes (e.g.,
matrix, array).  I've tried a few simple dummy examples and have not
had any success.

For example, if I try:

>Vol <- setRefClass("Vol", fields=list(x="numeric"), contains="matrix")

... no error is produced, *but* on displaying Vol, I see no mention of
the "matrix" class. Carrying on, if I then try to instantiate an
object:

>Vol$methods( initialize = function() {
>   setDataPart(.self,matrix(1:100,nrow=10))
>})
vol0 <- Vol$new(22)
Error in tryCatchOne(expr, names, parentenv, handlers[[1L]]) :
 node stack overflow

 I've tried a number of permutations with no luck. Any ideas? Is this
possible with Ref classes?

-jim


> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_CA.UTF-8
 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_CA.UTF-8
 [7] LC_PAPER=C LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] codetools_0.2-8 tools_2.14.1


-- 
=
Jim Nikelski, Ph.D.
Postdoctoral Research Fellow
Bloomfield Centre for Research in Aging
Lady Davis Institute for Medical Research
Sir Mortimer B. Davis - Jewish General Hospital
McGill University

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel