[Rd] Interfacing C-code (gets and printf) under WINDOWS (Visual C++)

2006-02-02 Thread Renard Didier
Hi

I try to develop a R interface to a set of C routines, in order to 
produce a R-package on Geostatistics.
My C-code uses interaction with the user as I use printf and gets 
statements.
I develop the code in a LINUX environment and do not face any problem 
having the questions and answers routed on my current Terminal.
When I tried to port the package on Windows, the problems began. No 
message was routed to the Console and I could not enter any answer. Let 
me first admit that I am not a specialist of the WINDOWS environment.
I started looking for an answer on the WEB and intercepted some pieces 
of answers ... but I did not succeed in getting a workable solution. 
This is the reason why I put this open question here today.

I did not find lots of information about the gets solution. Finally, I 
have chosen to use R_WriteConsole and R_ReadConsole which seemed to be 
promising solutions. I discovered an information saying that starting 
R-2.0.1, the include file R-interface.h could help me. This is the 
reason why I downloaded the latest version available on the R site 
(R-2.2.1). Unfortunately, I did not find such a file in the include 
directory. Moreover, in Visual C++ that I am using for building my DLL, 
I need to find the LIBRARY containing the objects of these two routines.
Did I do something wrong. Do I need to download other contributions 
first. Do I use incorrect routines ?

Thank you for your help.

Didier RENARD

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


[Rd] Problem with S3 to S4 transition

2010-03-16 Thread Renard Didier

Hello to everybody

I am developing a package using R and have the following problem:

I used to work in a mixture of S3 and S4 mechanism environment: as a 
matter of fact, I used to define my classes (say "DB" for illustration) 
using the setClass function (with representation field), and
I was using the S3 implicit mechanism writing the functions: print.DB 
and plot.DB.


Recently, I read some interesting papers on the use of S4 mechanism and 
was convinced that I would have some benefit in turning everything on S4 
formalism.
This is the reason why I simply renamed my previous functions into 
DB.print and DB.plot (by analogy with other functions where the Class 
name is the leading part of the name). My idea was to use the setMethod 
principle to set the DB.print function as the function for the "print" 
method on the "DB" class.
Therefore, in the .First.Lib file of my package, I introduced the 
setMethod line just after the setClass one, as in the following example:


   setClass("DB",
   representation(flag.grid = "logical", ndim = "numeric",
   x0 = "numeric", dx = "numeric", nx = "numeric",
   locators ="character",items = "data.frame"))
   setMethod("show","DB",function(object) DB.print(object))
   setMethod("print",signature(x="DB"),function(x,...) DB.print(x))
   setMethod("plot",signature(x="DB"),function(x,y,...) DB.plot(x))
   setMethod("["  ,signature(x="DB"),db0.getindex)
   setMethod("[<-",signature(x="DB"),db0.setindex)
   setMethod("$"  ,signature(x="DB"),db0.get)
   setMethod("$<-",signature(x="DB"),db0.set)

As one can notice, I use the same mechanism for SHOW, PLOT and PRINT.
Finally I created the package and imagined to use it using library statement

Surprisingly, when I used the library statement, the program tells me:
> standardGeneric for "print" defined from package "base"
> standardGeneric for "plot" defined from package "base"
and creates two objects in the .GlobalEnv, namely "plot" and "print" 
with the following contents:


> print
standardGeneric for "print" defined from package "base"

function (x, ...)
standardGeneric("print")

Methods may be defined for arguments: x
Use  showMethods("print")  for currently available ones.

Nothing similar for "show" although my use of setMethod is the same.

I see a main difference as "show" belongs to the "methods" library 
whereas the two other belong to the "base" library. Bu t I could not see 
how to avoid a user of my library to have these message and the two 
objects created.


I am allowed to set the method as I did (I think that I read something 
telling me that I could not do it with methods of the "base" library). 
Otherwiser how can I define the function DB.print as the required method 
for printing objects belonging to the "DB" class.


Thank in advance for you help.

--
Didier RENARD
Centre de Geosciences / Geostatistique
Ecole des Mines de Paris
35 Rue St Honore
77300 Fontainebleau

Tel: (1) 64 69 47 80
Fax: (1) 64 69 47 05

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


[Rd] Some more help on S4 mechanism

2010-03-22 Thread Renard Didier

Hello to the list

Some days ago, I placed a question on this maling-list and received an 
answer from Martin

that I tried to follow. Unfortunately, I am still puzzled by the next step.
I spent the whole Week-end in gathering information from the net.
Some of them are almost contridtcory and I lack a good document to help me.
So my first question would beL Is there a convenient document which tells
a standard user, who laready developped a package with S3, on how to migrate
to the S4 mechanism.

Secondly, this is my problem:
According to Martin, now I use a NAMESPACE (as follows):

import (methods)
exportPattern("^[^0]*$")
exportMethods(
   "[","[<-","$","$<-",
   "plot","print"
)
exportClasses(
   "anam","db","model","rule","vardir","vario","tokens","thresh"
)
useDynLib("RGeoS")
importFrom(graphics,plot)

More over, in the R directory, I have a zzz.lib with the following 
contents (.onLoad) :


".onLoad" <-
function(...)
{

   # Define the Classes #
   All0.Classes()

   # Define the environment variables #
   environ.load()
}

The file All0.Classes (which will not be exported ... see exportPattern) 
contains

all the class definitions (setClass functions)

Finally, I have some other functions, such as db.plot, which contain the 
following statement

(at the end of the file):

setMethod("plot", signature(x="db"), function(x,y,...) db.plot(x,...))

My questions:
- Should the setMethods be regrouped in a single file (as I read from 
the net).
- What are the differences between "R CMD check" and "R CMD INSTALL" as 
far as the steps are involved.


As a matter of fact:
- R CMD check finds that everything is OK
- R CMD INSTALL gives me a set of warnings of the following type:

Warning in matchSignature(signature, fdef, where) :
 in the method signature for function "[<-" no definition for class: "db"
I did not use the Collate option (that Martin suggested) as I am not 
sure of its syntax and where I should add these statements.


The package works fine anyhow but I would like to correct these warnings.

By the way, as I belong to an institute where we use Fedora Core 8, I am 
stuck with R 2.8.0.


An ultimate problem: I develop two packages P1 and P2 where P2 requires P1.
So I used the same architecture for both with NAMESPACE and .onLoad 
functions (in the zzz.lib files).


For P2, I mention that it depends upon P1 in the DESCRIPTION file. This 
information seems redundant with the NAMESPACE where I can add 
"import(P1)". Finally when, as a user, I load both by library() (first 
P1 then P2), I receive a message about function .onLoad being loaded twice.


How can I avoid this.

As you can see, I encountered several problems when converting my S3 
into S4. I would appreciate if someone could give me a complete 
information and a godd reference.


Thanks in advance.

--
Didier RENARD
Centre de Geosciences / Geostatistique
Ecole des Mines de Paris
35 Rue St Honore
77300 Fontainebleau

Tel: (1) 64 69 47 80
Fax: (1) 64 69 47 05

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