[Rd] Compatibility issue between lme4 and kml (operateur "[")

2015-05-26 Thread cgenolin
Hi all,

There is a compatibility issue between the package 'lme4' and my package
'kml'. I define the "[" operator. It works just fine in my package (1). If I
try to use the lme4 package, then it does no longer work (2). Moreover, it
has some kind of strange behavior (3). Do you know what is wrong? Any idea
of how I can correct that?

Thanks for your help
Christophe

--- 8< - Code for reproductible example ---
library(kml)
dn <- gald(1)
dn["traj"]
library(lme4)
dn["traj"]
setMethod(   ### Simplified version ###
  "[",
  signature=signature(x="ClusterLongData", i="character",
j="ANY",drop="ANY"),
  definition=function (x, i, j="missing", ..., drop = TRUE){
  x <- as(x, "LongData")
  return(x[i, j])
}
)
dn["traj"]
dn["traj"]

--- 8< - Execution of the previous code ---

> library(kml)
Le chargement a nécessité le package : clv
Le chargement a nécessité le package : cluster
Le chargement a nécessité le package : class
Le chargement a nécessité le package : longitudinalData
Le chargement a nécessité le package : rgl
Le chargement a nécessité le package : misc3d
> dn <- gald(1)

  ###
  (1] 
### (1) the "[" operator works just fine

> dn["traj"]
  t0   t1t2t3t4   t5   t6t7t8t9   t10
i1 -3.11 4.32  2.17  1.82  4.90 7.34 0.83 -2.70  5.36  4.96  3.16
i2 -7.11 1.40 -2.40 -2.96  4.31 0.50 1.25  0.52 -0.04  7.55  5.50
i3  2.80 6.23  6.08  2.87  2.58 2.88 6.58 -2.38  2.30 -1.74 -3.23
i4  2.24 0.91  6.50 10.92 11.32 7.79 7.78 10.69  9.15  1.07 -0.51

  ###
  (2) 
### using 'lme4', it does no longer work

> library(lme4)
Le chargement a nécessité le package : Matrix
Le chargement a nécessité le package : Rcpp
> dn["traj"]
Error in x[i, j] : 
  erreur d'évaluation de l'argument 'j' lors de la sélection d'une méthode
pour la fonction '[' : Erreur : l'argument "j" est manquant, avec aucune
valeur par défaut

  ###
  (3) 
### If I define again the "[", it does not work the first time I call it,
but it work the second time!
> setMethod(
+   "[",
+   signature=signature(x="ClusterLongData", i="character",
j="ANY",drop="ANY"),
+   definition=function (x, i, j="missing", ..., drop = TRUE){
+   x <- as(x, "LongData")
+   return(x[i, j])
+ }
+ )
[1] "["

### No working the first time I use it
> dn["traj"]
Error in dn["traj"] : 
  l'argument "j" est manquant, avec aucune valeur par défaut

### But working the second time
> dn["traj"]
  t0   t1t2t3t4   t5   t6t7t8t9   t10
i1 -3.11 4.32  2.17  1.82  4.90 7.34 0.83 -2.70  5.36  4.96  3.16
i2 -7.11 1.40 -2.40 -2.96  4.31 0.50 1.25  0.52 -0.04  7.55  5.50
i3  2.80 6.23  6.08  2.87  2.58 2.88 6.58 -2.38  2.30 -1.74 -3.23
i4  2.24 0.91  6.50 10.92 11.32 7.79 7.78 10.69  9.15  1.07 -0.51






--
View this message in context: 
http://r.789695.n4.nabble.com/Compatibility-issue-between-lme4-and-kml-operateur-tp4707670.html
Sent from the R devel mailing list archive at Nabble.com.

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


[Rd] Compatibility issues between Matrix and kml

2014-09-12 Thread cgenolin
Hi the list,

I am the maintainer of the package kml. I quite often receive some email
about a specific bug. The answer is always the same, I tell people to remove
the package Matrix, and then kml works fine.

I wonder what my code is not compatible with the Matrix package. Here is a
(simplified) version of the kml code :

--- 8< 
library(longitudinalData)

setClass(Class="CLD", contains=c("LongData","ListPartition"))

myCld <- new("CLD",
idAll=as.character(c(100,102,103,109,115,123)),
idFewNA=as.character(c(100,102,103,109,115,123)),
time=c(1,2,4,8,15), varNames="P",
traj=matrix(c(1,2,3,1,4, 3,6,1,8,10, 1,2,1,3,2, 4,2,5,6,3,
4,3,4,4,4, 7,6,5,5,4),6),
dimTraj=c(6,5), maxNA=3,  reverse=matrix(c(0,1),2,1)
)

setMethod("[",
 signature=signature(x="CLD", i="character", j="ANY",drop="ANY"),
 definition=function (x, i, j="missing", ..., drop = TRUE){
 x <- as(x, "LongData")
 return(x[i, j])
 }
)
# [1] "["

myCld["idAll"]
# [1] "100" "102" "103" "109" "115" "123"

--- 8< ---

This code works just fine, there is no error.

But if I load the package Matrix and I run the same code, I get:

--- 8< 
library(Matrix)
library(longitudinalData)

setClass(Class="CLD", contains=c("LongData","ListPartition"))

myCld <- new("CLD",
idAll=as.character(c(100,102,103,109,115,123)),
idFewNA=as.character(c(100,102,103,109,115,123)),
time=c(1,2,4,8,15), varNames="P",
traj=matrix(c(1,2,3,1,4, 3,6,1,8,10, 1,2,1,3,2, 4,2,5,6,3,
4,3,4,4,4, 7,6,5,5,4),6),
dimTraj=c(6,5), maxNA=3,  reverse=matrix(c(0,1),2,1)
)

setMethod("[",
 signature=signature(x="CLD", i="character", j="ANY",drop="ANY"),
 definition=function (x, i, j="missing", ..., drop = TRUE){
 x <- as(x, "LongData")
 return(x[i, j])
 }
)

# [1] "["

myCld["idAll"]
# Error in myCld["idAll"]:
#   Argument "j" is missing, with no default value
--- 8< 

Any idea of what is going wrong?

Christophe




--
View this message in context: 
http://r.789695.n4.nabble.com/Compatibility-issues-between-Matrix-and-kml-tp4696885.html
Sent from the R devel mailing list archive at Nabble.com.

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


[Rd] Define S4 methods for 'plot'

2011-11-09 Thread cgenolin
Hi the list
I am creating a package and I have a problem to define a S4 method for plot.
I define a class 'A' and a class 'B'. I want to define a function plot for
signature c(A,missing) and another method plot for signature c(A,B). My code
is the following :

In /package/R/ directory:
--- main.R ---
setGeneric("plot",function(x,y,...){standardGeneric("plot")})
Aplot <- function(x,paramTraj=3){. . . .}
setMethod("plot",signature=c(x="A",y="missing"),Aplot)

ABplot <- function(x,y,paramTraj=5){. . . .}
setMethod("plot",signature=c(x="A",y="B"),ABplot)
---

In the root directory /package/
--- NAMESPACE ---
exportMethods("plot",. . . .)
exportClasses("A","B")
--
When I run the code (source("main.r")), every thinks works fine, either plot
on object of class 'A', on 'A,B' or on numeric plot(3). 

The R CMD check bug on an example using plot(3).
The R CMD build works just fine. But if I try to install the package from
the builded file, I get the message:
The following object(s) are masked from 'package:graphics':
plot.

And then, I cannot use the classical function plot: plot on object 'A'
works, but plot(1) does not.

I try, reading some recent post on r-devel to remove the line 'setGeneric'
but it does not works (which does not surprise me since getGeneric("plot")
gives a NULL results).
 
Any idea of what goes wrong?

Christophe


--
View this message in context: 
http://r.789695.n4.nabble.com/Define-S4-methods-for-plot-tp4020750p4020750.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Define S4 methods for 'plot'

2011-11-10 Thread cgenolin
I works, thank you very much.

--
View this message in context: 
http://r.789695.n4.nabble.com/Define-S4-methods-for-plot-tp4020750p4023508.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Comments in the DESCRIPTION file

2013-05-01 Thread cgenolin
Hi all,

Since R 3.0.0, the '#' does no longuer works for comments.
But as noticed above, comments can be introduce by 'anyWord:' or
'myComment;' or 'toto:'.

Since '#' can be used to name a field, we can also used '#:' or '###:' (or
even '%:' for LaTeX's fans).

So '#:' is a new possible way for adding comments in DESCRIPTION file.

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/Comments-in-the-DESCRIPTION-file-tp4648678p4665892.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Comments in the DESCRIPTION file

2013-05-02 Thread cgenolin
Hi,

I am not that familiar with the DCF... But R seems to accept # quite easely.
More precisely:

Before posting my message, I try it on a small package: R CMD check or R CMD
INSTALL did not make any warning or error (whereas they do if I use '#'
alone). 

After reading your response, I dig a bit more. The source of my DESCRIPTION
file was:

--- 8< --
#:
###: This is some kind of 'section 1'
###:
Package: packBasic1
Title: Very simple package
Version: 0.9.2
License: GPL (>=2.0)
Description: A package
#:
#:
#:
###: This is 'section 2'
###:
Author: Christophe Genolini
Maintainer: Christophe Genolini 
--- 8< --

The DESCRIPTION file after installation was: 

--- 8< --
#:
###:
Package: packBasic1
Title: Very simple package
Version: 0.9.2
License: GPL (>=2.0)
Description: A package
#:
Author: Christophe Genolini
Maintainer: Christophe Genolini 
Built: R 3.0.0; ; 2013-05-02 06:50:57 UTC; windows
--- 8< --

So I guess there was a problem.
But if I number the comments line, then it works:

--- 8< -
#1:
###2: This is some kind of 'section 1'
###3:
Package: packBasic1
Title: Very simple package
Version: 0.9.2
License: GPL (>=2.0)
Description: A package
#4:
#5:
#6:
###7: This is 'section 2'
###8:
Author: Christophe Genolini
Maintainer: Christophe Genolini 
Built: R 3.0.0; ; 2013-05-02 06:49:27 UTC; windows
--- 8< -

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/Comments-in-the-DESCRIPTION-file-tp4648678p4666017.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Comments in the DESCRIPTION file

2013-05-02 Thread cgenolin
So it IS curently accepted, but may NOT be in the futur. Thanks for your
answer.

So I guess that using 
--- 8< -
%1: 
%%%2: Section 1
%%%3
...
--- 8< -

is correct, isn't it?

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/Comments-in-the-DESCRIPTION-file-tp4648678p4666058.html
Sent from the R devel mailing list archive at Nabble.com.

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


[Rd] Data in packages: save or write.table?

2013-05-02 Thread cgenolin
Hi all,
I am trying to understand Writing R Extension...
Section 1.1.5, data: I include two datasets in a package, one using 'save',
the other using 'write.table':

--- 8< 
myData1 <- data.frame(x=1:10)
write.table(myData1,file="myData1.txt")
myData2 <- data.frame(x=2:10)
save(myData2,file="myData2.Rdata")
--- 8< 

Then R CMD check aks me to document myData1, but does not ask me to document
myData2.
In the R session, after 'library(myPack)', the data 'myData2' is
automatically present in the session while myData1 require the use of
data(myData1). Is that correct, or is there a bug in my code?

Christophe



--
View this message in context: 
http://r.789695.n4.nabble.com/Data-in-packages-save-or-write-table-tp4666061.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Possible improvements/clarifications for R-forge (Was: Re: Using SVN + SSH on windows)

2010-03-29 Thread cgenolin



Getting back to the original poster who may have been forgotten in all
this, alternatives are switching to Linux and using R-Forge with that
(if such a switch in platforms is feasible) or using googlecode
(that's the largest repository of R projects outside of CRAN with 237
R projects listed -- it uses https rather than ssh which eliminates
all the problems).


Naive question: Is it not possible to make R-forge works either with 
ssh or with https?


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


[Rd] bug in mmlcr ? (PR#10576)

2008-01-15 Thread cgenolin
Hi the list.

Is there a bug in mmlcr package ?
The following code does not compile:

mmlcrTest <- function(dataW){
  dataL <-
reshape(dataW,idvar="id",timevar="T",varying=list("T0","T1","T2"),direction="long",v.names="score")

  resultR <- mmlcr(outer= ~ 1 | id,
   components = list(list(formula = score~1+T,class=
"normlong")), n.groups=3,
   data=dataL,
   max.iter=500
   )
  plot(resultR)
}
mmlcrTest(dataW)

The error is (translate from french):
"Error in inherits(x, "data.frame") : objet "dataL" not find"

It seems that mmlcr does not look for the data at the right place since
it did find dataL if we set it a a global variable but it does not find
it if we define it in a function.

Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


[Rd] S4: dumpMethod (PR#11053)

2008-03-29 Thread cgenolin
Full_Name: Christophe Genolini
Version: 2.6.2
OS: Windows XP
Submission from: (NULL) (82.225.59.146)


*This is a mail that I post on r-help: *

>> It seems that the dumpMethod does not work.

setClass("A",representation(a="numeric"))
setMethod("plot","A",function(x,y,...){cat("A\n")})
dumpMethod("plot","A",file="")
#setMethod("plot", "A",
#NULL
#)
#[1] ""

> Answer from Martin Maechler

> dumpMethod() has not been updated when the internal method
> definition (and storage) code has been changed.
> Consequently, it looks pretty broken to me, as well.
>
> OTOH, I have never seen any need to use it,
> since I only work with *.R files which I write and comment and ..
> and never would want to replace with anything dumped...
>
> Do you want to submit a (legitimate (!)) bug report to R-bugs ?

Well, I did not submit a bug concerning a (may be) useless method... 
But today, I find it usefull: "package.skeleton" use dump.
So a "package.skeleton.S4" might need dumpMethod...

Christophe

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


Re: [Rd] tests Rin and Rout

2008-04-01 Thread cgenolin
Martin Maechler <[EMAIL PROTECTED]> a écrit :

>> "CG" == Christophe Genolini <[EMAIL PROTECTED]>
>> on Mon, 31 Mar 2008 00:31:55 +0200 writes:
>
>>>
>>> Generally I find it's good to look at examples that work.
>>> For examples of packages using tests, look at source
>>> packages on CRAN.  Run the tests on them (using R CMD
>>> check), and see what gets produced.
>>>
>CG> Do you have the name of a package that use it ? I try
>CG> the 10 first package, and 10 other at random, but none
>CG> of them use tests...
>
> hmm, I see 219 out 1378 CRAN packages having a 'tests'
> subdirectory, so it seems you have been a bit unlucky. ;-)

Do you imply that I say I try and I did not ?
Well, lets check that :

P_unluck_1   <- 1-(219/1379)
(P_unluck_10 <- P_unluck_1^10)
[1] 0.1773933

So P>0.05, once can not say that I am not a liar.
Further investigation are needed :-)

> Isn't all this is explained nicely in the "Writing R Extensions" Manual?

NO ! There is 8 lines on it, and the structure of the Rin and Rout is 
not given. The writing R Ext. say "the Test code can be in .R or in 
.Rin" but I do not know what "test code" is suppose to be. I try simple 
things like some function with argument, but it does not works. I try 
more complicated things, I did not manage to find the right things to 
do.

It also say ".Rin file containing code which in turn in .R", but there 
is also no information about the what the .Rin should be. May be it is 
obvious for some people, but not for me.

> Or are there sections we should expand ?

I do not know, if there is only few people using it, may be it is not 
worth. I guess you have so many other thinks to do...
On the other hand, if some tool are to difficult to understand, it is 
normal that people do not use them... I don't know.

I will work on package example that Pr Ripley point to me. Then when I 
will have understand the way it works, would you like me to add little 
paragraph in "Writing R extention" ? I mean, not an paragraph by expert 
but a paragraph by a regular medium level user for some other regular 
medium level user.

> For answering your subsequent questions, you should probably
> both look at an example package *and* read the 'Writing R
> Extensions' manual a bit more "closely".

Well, I try to not disturb people for little obvious thinks. I can tell 
you I did work hard before asking, specialy before asking on r-devel...

Christophe





Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


Re: [Rd] tests Rin and Rout

2008-04-01 Thread cgenolin
>> hmm, I see 219 out 1378 CRAN packages having a 'tests'
>> subdirectory, so it seems you have been a bit unlucky. ;-)
>
>
>
> How unlucky exactly?
>
>
> > fisher.test(matrix(c(0,20,219,1159),2,2))
>

Hey, no, I desagree ! I random 10, the 10 first I take the ten first 
package. So this in not random.
May be the people that chose a name package starting with 'a' does not 
like using 'tests'...

So we have to do fisher.test(matrix(c(0,10,219,1159),2,2))


Fisher's Exact Test for Count Data

data:  matrix(c(0, 10, 219, 1159), 2, 2) p-value = 0.3783
alternative hypothesis: true odds ratio is not equal to 1 95 percent 
confidence interval:
0.00 2.380931 sample estimates:
odds ratio

I am not *that* unlucky

Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


[Rd] R 2.7 package.skeleton

2008-04-13 Thread cgenolin
Hi the devel list

I am testing package.skeleton in R 2.7 (download today). I get an error 
that I do not understand. I guess it is not an error from my code since 
I have no probleme when I source it. So is it a error in 
package.skeleton?

Here is my code :


--- 8< -- File essai.r -
setClass(
   Class="ClusterizLongData",
   representation=representation(
 clusterizS="list"
   ),
   prototype=prototype(
 clusterizS=list(c2=list(),c3=list())
   )
)
--- 8< -


package.skeleton("kmt",code_files=c("essai.r"))

Erreur dans .prototype(...) :  l'argument "list" est manquant, avec 
aucune valeur par défaut

[approximative translation :
Error in .prototype(...) :
  the argument "list" is missing, with no default value
]


Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


[Rd] R2.7 package.skeleton II

2008-04-13 Thread cgenolin
Hi again

I get an other error on an other file. More precisely,

package.skeleton("kmt2",code_files=c("function.r","partition.r","longData.r","imputation.r","clusterization.r"))

I put 5 files in code_files,  everything seems to work fine, the 
directory "kmt2" is created, but I get an message :

Création des répertoires...
Création de DESCRIPTION...
Création de 'Read-and-delete-me'...
Recopiage des fichiers de code...
Création des fichiers d'aide ...
Error in le > 0 :  comparaison (6) possible seulement pour les types 
liste et atomique
De plus : Warning message:
In is.na(le) :
  is.na() appliqué à un objet de type 'S4' qui n'est ni une liste, ni un vecteur
Erreur dans package.skeleton("kmt8", code_files = c("function.r", 
"partition.r",  :  Error in le > 0 :  comparaison (6) possible 
seulement pour les types liste et atomique


If someone want, I can send my complete files, but I did not manage to 
precisely find the part of the programme that provoque this error (as I 
did in my previous bug repport).

Christophe


Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


Re: [Rd] R 2.7 package.skeleton

2008-04-13 Thread cgenolin
> However, try this example with the corrected package.skeleton() as well.

I did, it is working

Thanks

Christophe

>
>
> John Chambers wrote:
>> Well, the workaround does not help much.  The source files will be 
>> copied to the new package, but they are not evaluated (because 
>> package.skeleton requires list= to be missing).  Therefore you won't 
>> have the documentation files reflecting the contents of essai.r
>>
>> So, for the moment, this just seems to be a bug needing fixing.  
>> Merci et ne quittez pas.
>>
>> John
>>
>> John Chambers wrote:
>>
>>> Seems to be an R bug in evaluating the source code in your file.
>>>
>>> As the message says, something is trying to evaluate the "list" 
>>> argument to package.skeleton.  My guess is that it's the 
>>> unfortunate choice of "list" as an argument name interacting with 
>>> your use of list() in the code in essai.r  (By the language 
>>> semantics a function and a non-function with the same name _should_ 
>>> be ok, but the fact that there is no default may be triggering a 
>>> difficulty in sys.source())
>>>
>>> To make life more difficult, package.skeleton does not seem to like 
>>> a zero-length list= argument either.  The following is an ugly way 
>>> to avoid the error, by creating a list with one object.
>>>
>>>  > nul <- ""
>>>  > package.skeleton("kmt", code_files = "essai.r", list = "nul")
>>> Creating directories ...
>>> Creating DESCRIPTION ...
>>> Creating Read-and-delete-me ...
>>> Copying code files ...
>>> Making help files ...
>>> Done.
>>> Further steps are described in './kmt/Read-and-delete-me'.
>>>
>>>
>>>
>>>
>>> [EMAIL PROTECTED] wrote:
>>>
 Hi the devel list

 I am testing package.skeleton in R 2.7 (download today). I get an 
 error that I do not understand. I guess it is not an error from my 
 code since I have no probleme when I source it. So is it a error 
 in package.skeleton?

 Here is my code :


 --- 8< -- File essai.r -
 setClass(
Class="ClusterizLongData",
representation=representation(
  clusterizS="list"
),
prototype=prototype(
  clusterizS=list(c2=list(),c3=list())
)
 )
 --- 8< -


 package.skeleton("kmt",code_files=c("essai.r"))

 Erreur dans .prototype(...) :  l'argument "list" est manquant, 
 avec aucune valeur par défaut

 [approximative translation :
 Error in .prototype(...) :
   the argument "list" is missing, with no default value
 ]


 Christophe

 
 Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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



>>> __
>>> R-devel@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>
>>  [[alternative HTML version deleted]]
>>
>>   
>>
>> __
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>




Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre

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


[Rd] S4: what to put in initialize, validity and constructor?

2008-05-02 Thread cgenolin

Hi the list,

I have some trouble using validity, intialize and the constructor. More 
precisely, what should go where?

Here is a toy exemple (seams long, but the code is very simple):

I want to define an object with two slots a and b with the properties that
b will be either empty or the scare of a. Example of valid object :
 a=  b=
 a=2 b=
 a=3 b=9

So I define my object and the validity function :

setClass(
   "A",
   representation(a="numeric",b="numeric"),
   validity=function(object){
   cat("Validity\n")
   if(length([EMAIL PROTECTED])!=0){
   if(length([EMAIL PROTECTED])==0){stop("Can not have empty a and non 
emty b")}else{}

   if([EMAIL PROTECTED]@b){stop("b is not the scare of a")}else{}
   }else{}
   return(TRUE)
   }
)

It works:

new("A")
new("A",a=2,b=4)
try(new("A",b=4))
new("A",a=2)
try(new("A",a=2,b=3))


Then I define the initialize function. When b is givent but not a, the 
initialise function set a to sqrt(b).


setMethod(
   "initialize",
   "A",
   function(.Object,a,b){
   if(missing(a)&!missing(b)){
   [EMAIL PROTECTED] <- b
   [EMAIL PROTECTED] <- sqrt(b)
   }else{}
   if(!missing(a)&missing(b)){
   [EMAIL PROTECTED] <- a
   }else{}
   if(!missing(a)&!missing(b)){
   [EMAIL PROTECTED] <- a
   [EMAIL PROTECTED] <- b
   }else{}
   validObject(.Object)
return(.Object)
   }
)

It is fine:

new("A")
new("A",a=2,b=4)
new("A",b=9)
new("A",a=2)
try(new("A",a=2,b=3))


Then I want to set the constructor

A <- function(a,b){
   return(new("A",a,b))
}

But this does not work:
A()
A(a=2,b=4)
A(b=9)
A(a=2)


The following does not work either:

A <- function(a=numeric(),b=numeric()){
   return(new("A",a,b))
}

A()
A(a=2,b=4)
A(b=9)
A(a=2)

So is there a way to define the constructor A without dealing again 
with all the missing&missing staff like in initialize?


Christophe

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


Re: [Rd] S4: what to put in initialize, validity and constructor?

2008-05-02 Thread cgenolin



Do not change initialize!


As I sat, this is a toy example. In my real example, initialize does a 
lot of things like calculation of quality indice (b is not the scare of 
a, but B1, B2 and B3 are the the within matrix of A after imputation 
with 3 differents methods), giving names to some matrix column and so 
on. So I seams costfull to not use an initialize.



Define constructors:

setGeneric("A", function(a,b,...) standardGeneric("A"))

setMethod("A", signature(a="missing",b="missing"),
 function(a,b,...) A(as.numeric(1:10),...) ## calls the one below
)

setMethod("A", signature(a="A",b="missing"),
 function(a,b,...) a
)

setMethod("A", signature(a="ANY",b="ANY"),
 function(a,b,...) new("A",a=as.numeric(a),b=as.numeric(b),...)
)

setMethod("A", signature(a="ANY",b="missing"),
 function(a,b,...) A(a,a,...) ## Calls the one above
)

etc.

In words:
1) validity should return a character in case of errors
2) default initializer usually does the job
3) define constructors as methods to allow different signatures and
  conversions from other classes
4) If you derive your class from numeric, rather than add slots,
  the performance will be much better and you will get default
  behaviour of numeric, i.e.

setClass("A",
 representatiom("numeric", b="numeric") etc

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
[EMAIL PROTECTED]


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 02 May 2008 15:41
To: r-devel@r-project.org
Subject: [Rd] S4: what to put in initialize, validity and constructor?

Hi the list,

I have some trouble using validity, intialize and the
constructor. More precisely, what should go where?
Here is a toy exemple (seams long, but the code is very simple):

I want to define an object with two slots a and b with the
properties that b will be either empty or the scare of a.
Example of valid object :
  a=  b=
  a=2 b=
  a=3 b=9

So I define my object and the validity function :

setClass(
"A",
representation(a="numeric",b="numeric"),
validity=function(object){
cat("Validity\n")
if(length([EMAIL PROTECTED])!=0){
if(length([EMAIL PROTECTED])==0){stop("Can not have empty
a and non emty b")}else{}
if([EMAIL PROTECTED]@b){stop("b is not the scare
of a")}else{}
}else{}
return(TRUE)
}
)

It works:

new("A")
new("A",a=2,b=4)
try(new("A",b=4))
new("A",a=2)
try(new("A",a=2,b=3))


Then I define the initialize function. When b is givent but
not a, the initialise function set a to sqrt(b).

setMethod(
"initialize",
"A",
function(.Object,a,b){
if(missing(a)&!missing(b)){
[EMAIL PROTECTED] <- b
[EMAIL PROTECTED] <- sqrt(b)
}else{}
if(!missing(a)&missing(b)){
[EMAIL PROTECTED] <- a
}else{}
if(!missing(a)&!missing(b)){
[EMAIL PROTECTED] <- a
[EMAIL PROTECTED] <- b
}else{}
validObject(.Object)
return(.Object)
}
)

It is fine:

new("A")
new("A",a=2,b=4)
new("A",b=9)
new("A",a=2)
try(new("A",a=2,b=3))


Then I want to set the constructor

A <- function(a,b){
return(new("A",a,b))
}

But this does not work:
A()
A(a=2,b=4)
A(b=9)
A(a=2)


The following does not work either:

A <- function(a=numeric(),b=numeric()){
return(new("A",a,b))
}

A()
A(a=2,b=4)
A(b=9)
A(a=2)

So is there a way to define the constructor A without dealing
again with all the missing&missing staff like in initialize?

Christophe

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




**
The contents of this email are for the named addressee(s) only.
It contains information which may be confidential and privileged.
If you are not the intended recipient, please notify the sender
immediately, destroy this email and any attachments and do not
otherwise disclose or use them. Email transmission is not a
secure method of communication and Man Investments cannot accept
responsibility for the completeness or accuracy of this email or
any attachments. Whilst Man Investments makes every effort to keep
its network free from viruses, it does not accept responsibility
for any computer virus which might be transferred by way of this
email or any attachments. This email does not constitute a request,
offer, recommendation or solicitation of any kind to buy, subscribe,
sell or redeem any investment instruments or to perform other such
transactions of any kind. Man Investments reserves the right to
monitor, record and retain all electronic communications through
its network to ensure the integrity of its systems, for record
keeping and regulatory purposes.

Visit us at: www.maninvestments.com

**




__
R-

[Rd] k means

2008-05-12 Thread cgenolin

Hi the devel list,

I am using K means with a non standard distance. As far as I see, the 
function kmeans is able to deal with 4 differents algorithm, but not 
with a user define distance.


In addition, kmeans is not able to deal with missing value whereas 
there is several solution that k-means can use to deal with them ; one 
is using a distance that takes the missing value in account, like a 
distance with Gower adjustement (which is the regular distance dist() 
used in R).


So is it possible to adapt kmeans to let the user gives an argument 
'distance to use'?


Christophe

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


Re: [Rd] k means

2008-05-16 Thread cgenolin

Hi the list

I try the flexclust, but I do not manage to see what is wrong in my 
(very simple) code...

Will you have few minutes to check it?

Thanks for your help.

Christophe
--- 8< 
data  <- rbind(c(1,2 ,NA,4 ),
  c(1,1 ,NA,1 ),
  c(2,3 ,4 ,5 ),
  c(2,2 ,2 ,2 ),
  c(3,NA,NA,6 ),
  c(3,NA,NA,3 ),
  c(2,4 ,4 ,NA),
  c(2,3 ,2 ,NA))

distTest <- rbind(c(0,0,0,0),
 c(1,1,1,1))

distNA <- function(x,centers){
   z <- matrix(0,nrow=nrow(x),ncol=nrow(centers))
   for(k in 1:nrow(centers)){
   z[,k]<- apply(x,1,function(x){dist(rbind(x,centers[k,]))})
   }
   z
}

distNA(data,distTest)

km <- kccaFamily(dist=distNA,cent=colMeans)
kcca(x=data,k=2,family=km)
kcca(x=data,k=3,family=km)

--- 8< 







On Mon, 12 May 2008 19:24:55 +0200,
cgenolin  (c) wrote:


 > Hi the devel list,
 > I am using K means with a non standard distance. As far as I see, the
 > function kmeans is able to deal with 4 differents algorithm, but not
 > with a user define distance.

 > In addition, kmeans is not able to deal with missing value whereas
 > there is several solution that k-means can use to deal with them ; one
 > is using a distance that takes the missing value in account, like a
 > distance with Gower adjustement (which is the regular distance dist()
 > used in R).

 > So is it possible to adapt kmeans to let the user gives an argument
 > 'distance to use'?

As Bill Venables already pointed out that makes not too much sense,
especially as there are already R functions for doing that. Package
flexclust implements a k-means-type clustering algorithm where the
user can provide arbitrary distance measures, have a look at

http://www.stat.uni-muenchen.de/~leisch/papers/Leisch-2006.pdf

The code you need to write for using a new distance measure is
minimal, and there are two examples in the paper describing in detail
what needs to be done.

Hope this helps,
Fritz Leisch

--
---
Prof. Dr. Friedrich Leisch

Institut für Statistik  Tel: (+49 89) 2180 3165
Ludwig-Maximilians-Universität  Fax: (+49 89) 2180 5308
Ludwigstraße 33
D-80539 München http://www.statistik.lmu.de/~leisch
---
  Journal Computational Statistics --- http://www.springer.com/180
 Münchner R Kurse --- http://www.statistik.lmu.de/R
---




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


[Rd] package.skeleton does invalide regular name...

2008-07-15 Thread cgenolin

Hi the list,

I am using package.skeleton on a file that has a very classic name, but 
package.skeleton detect it as a invalid name :


--- 8< ---
package.skeleton(name="packClassicBis",code_files="./packClassic/R/progClassic.R")

Création des répertoires...
Création de DESCRIPTION...
Création de 'Read-and-delete-me'...
Recopiage des fichiers de code...
Création des fichiers d'aide ...
Terminé.
Les étapes suivantes sont décrites dans './packClassic4/Read-and-delete-me'.
Warning message:
In package.skeleton(name = "packClassic4", code_files = 
"./packClassic/R/progClassic.R") :

 Nom(s) de fichier(s) invalide(s) pour du code R ./packClassic4/R:
 'progClassic.R'
sont maintenant renommés vers 'z.R'
--- 8< ---

It create the file "zprogClassic.R" in directorie "packClassicBis\R"
Is there something wrong in my code or is it a bug in package.skeleton ?

Christophe

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


[Rd] package.skeleton does invalide regular name, bis... (PR#12020)

2008-08-07 Thread cgenolin
Hi the list,

I guess I find an other bug (the first one is at the end off this mail) 
in package.skeleton. It occurs when we give as code_file some file that 
are not in the current directories.

If we give a single file to code_file (like code_file=3D"riri/fifi.R"), 
it does not reconize fifi.R as a regular name and change it to 
riri/zfifi.R

If we give several file to code_file (like 
code_file=3Dc("riri/titi.R","riri/loulou.R")), it does not reconize 
titi.R as a regular name, change it to toto/ztiti.R and we get an error 
on riri/loulou.R

Christophe

--- 8< -
> package.skeleton(name=3D"miniKml",code_files=3Dc("miniKml/R/global.R","mi=
niKml/R/global2.R"),force=3DTRUE)

Cr=E9ation des r=E9pertoires...
Cr=E9ation de DESCRIPTION...
Cr=E9ation de 'Read-and-delete-me'...
Recopiage des fichiers de code...
Erreur dans file.rename(from =3D file.path(code_dir, bn), to =3D 
file.path(code_dir,  :  'source' doit =EAtre une cha=EEne de caract=E8res u=
nique
De plus : Warning message:
In package.skeleton(name =3D "miniKml", code_files =3D c("miniKml/R/global.=
R",  :
  Nom(s) de fichier(s) invalide(s) pour du code R ./miniKml/R:
  'global.R', 'global2.R'
sont maintenant renomm=E9s vers 'z.R'
--- 8< --


> Hi the list,
>
> I am using package.skeleton on a file that has a very classic name, 
> but package.skeleton detect it as a invalid name :
>
> --- 8< ---
> package.skeleton(name=3D"packClassicBis",code_files=3D"./packClassic/R/pr=
ogClassic.R")
>
> Cr=E9ation des r=E9pertoires...
> Cr=E9ation de DESCRIPTION...
> Cr=E9ation de 'Read-and-delete-me'...
> Recopiage des fichiers de code...
> Cr=E9ation des fichiers d'aide ...
> Termin=E9.
> Les =E9tapes suivantes sont d=E9crites dans './packClassic4/Read-and-dele=
te-me'.
> Warning message:
> In package.skeleton(name =3D "packClassic4", code_files =3D 
> "./packClassic/R/progClassic.R") :
>  Nom(s) de fichier(s) invalide(s) pour du code R ./packClassic4/R:
>  'progClassic.R'
> sont maintenant renomm=E9s vers 'z.R'
> --- 8< ---
>
> It create the file "zprogClassic.R" in directorie "packClassicBis\R"
> Is there something wrong in my code or is it a bug in package.skeleton ?
>
> Christophe
>
> 
> Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
>
>
>

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


Re: [Rd] unlist change the ordered type

2008-10-26 Thread cgenolin

"Charles C. Berry" <[EMAIL PROTECTED]> a écrit :


On Fri, 24 Oct 2008, Christophe Genolini wrote:


Hi the list,

unlist respect the all the atomic type except orderd (it change of 
ordered into factor) :


### integer
class(unlist(list(1:5,1:3)))
#[1] "integer"

### numeric
class(unlist(list(1.2,3.5)))
#[1] "numeric"

### character
class(unlist(list("e","e")))
#[1] "character"

### factor
class(unlist(list(factor("e"),factor("e"
#[1] "factor"

### ordered
class(unlist(list(ordered("e"),ordered("e"
#[1] "factor"


Consider

unlist(list(ordered(1:2),ordered(letters[1:4])))

Since one cannot deduce what ordering should apply, the best that can 
be done is to demote all arguments to factors.


This is the general case. Only in the special case in which all list 
elements are of class 'ordered' and the levels attributes are the 
same would this be sensible.


This "only special" case is quite common since the use of lapply on 
ordered gives such a list


Christophe

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


[Rd] matplot does not considere the parametre lend (PR#13619)

2009-03-23 Thread cgenolin
Full_Name: Christophe Genolini
Version: 2.8.1, but also 2.9
OS: Windows XP
Submission from: (NULL) (82.225.59.146)


I am using matplot with the option lend="butt", but only the first line (the
black) is printed correctly  :

> matplot(matrix(1:9,3),type="c",lwd=10,lty=1,lend="butt")

Gabor Grothendieck find the problem in matplot code:
the ... is passed to plot (which plots the first series) but not to lines (which
plots the rest):

if (!add) {
ii <- ii[-1]
plot(x[, 1], y[, 1], type = type[1], xlab = xlab, ylab = ylab,
xlim = xlim, ylim = ylim, lty = lty[1], lwd = lwd[1],
pch = pch[1], col = col[1], cex = cex[1], bg = bg[1],
...)
}
for (i in ii) {
lines(x[, i], y[, i], type = type[i], lty = lty[i], lwd = lwd[i],
pch = pch[i], col = col[i], cex = cex[i], bg = bg[i])
}

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


[Rd] savePlot export "strange" eps (PR#13620)

2009-03-23 Thread cgenolin
Full_Name: Christophe Genolini
Version: 2.8.1
OS: Windows XP
Submission from: (NULL) (82.225.59.146)


savePlot export "eps" graph that seems to be incorrect. 

Trying to incorporate them in a LaTeX file, I get : 
++
Cannot determine size of graphics in foo.eps (no BoundingBox)
--

Trying to open them with GSview, I get :
++
GSview 4.9 2007-11-18
AFPL Ghostscript 8.54 (2006-05-17)
Copyright (C) 2005 artofcode LLC, Benicia, CA.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Displaying non DSC file C:/Documents and Settings/Christophe/Mes
documents/Recherche/Trajectoires/kmeal/trajectories/testsDev/toti.eps
Error: /undefined in 
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--  
--nostringval--   2   %stopped_push   --nostringval--   --nostringval--   false 
 1   %stopped_push   1   3   %oparray_pop   1   3   %oparray_pop   1   3  
%oparray_pop   1   3   %oparray_pop   .runexec2   --nostringval--  
--nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1130/1686(ro)(G)--   --dict:0/20(G)--   --dict:74/200(L)--
Current allocation mode is local
Last OS error: No such file or directory

--- Begin offending input ---
   €      L   z  f  C  fC   EMF   $6  7     
   l       °    €— ° G r a p h A p p %        €%
       €%        €%        €%        €%        €%        €%       
€%        €%        €%        €%        €K   @   0              
N   N   y  @  N   N   y  @  %        €%        €:      
   _   8      8   8 
   %               
   ;            l   *  6      Z  õ  <      @      f   ï  `  0  %   
    €(         %        €%        €K   @   0               N   N 
 y  @  N   N   y  @  %        €%        €:      
   _   8      8   8 
   %               
   ;            m  ñ  6      Z  »  <      @      g  µ  `  ÷  %   
    €(         %        €%        €K   @   0             
 ¡  ¡  ¡  ¡  %        €%        €:      
   _   8      8   8    
--- End offending input ---
file offset = 1024
gsapi_run_string_continue returns -101

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