[R] building a package that contains S4 classes and methods

2008-09-09 Thread Marie Pierre Sylvestre
Hello R users,

I am trying to make a my first package and I get an error that I can
understand. The package is build out of three files (one for functions, 1
for s4 classes and 1 for s4 methods).

Once I source them I run 

package.skeleton( name=TDC )

within a R session and I get 

Creating directories ...
Creating DESCRIPTION ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './TDC/Read-and-delete-me'.
Warning messages:
1: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
2: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
3: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
4: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse may be incomplete


I keep going in spite of the warnings with 
R CMD check --no-examples TDC

and I get 
* checking for working pdflatex ... OK
* using log directory
'/home/mariepierre/Packages/PermAlgo/PermAlgo/PermAlgo2/TDC.Rcheck'
* using R version 2.7.1 (2008-06-23)
* using session charset: UTF-8
* checking for file 'TDC/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'TDC' version '1.0'
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking whether package 'TDC' can be installed ... ERROR
Installation failed.

The error file says:
 
* Installing *source* package 'TDC' ...
** R
** preparing package for lazy loading
Error in parse(n = -1, file = file) : unexpected '' at
102: `.__C__BindArgs` -
103: 
Calls: Anonymous - code2LazyLoadDB - sys.source - parse
Execution halted
ERROR: lazy loading failed for package 'TDC'
** Removing
'/home/mariepierre/Packages/PermAlgo/PermAlgo/PermAlgo2/TDC.Rcheck/TDC'

The problem is with my classes and methods. The respective files contain:

setClass(BindArgs,  signature( function ))
setClass(BindArgs2, signature( function )) 

and

setMethod(initialize, BindArgs, function( .Object, f, ... )
  callNextMethod( .Object, function( x ) f( x, ... ) )) 

setMethod(initialize, BindArgs2, function( .Object, f, ...)
  callNextMethod( .Object, function( x, y ) f( x, y, ... ) )) 

Everything works well within a R session but I can build the package.

If I look at the internal R file that this created I get

`.__C__BindArgs` -
S4 object of class structure(classRepresentation, package = methods)
`.__C__BindArgs2` -
S4 object of class structure(classRepresentation, package = methods)
`.__M__initialize:methods` -
S4 object of class structure(MethodsList, package = methods)
`.__T__initialize:methods` -
environment

Well, let just say that I am new to classes so this confuses me greatly. I
have checked the documentation and tried a few things but I reached my
personal limits!

I am using R 2.7.1 on Linux Fedora 8.

Any comments on what is happening and/or help would be greatly appreciated.

MP

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] building a package that contains S4 classes and methods

2008-09-09 Thread Peter Dalgaard

Marie Pierre Sylvestre wrote:

Hello R users,

I am trying to make a my first package and I get an error that I can
understand. The package is build out of three files (one for functions, 1
for s4 classes and 1 for s4 methods).

Once I source them I run 


package.skeleton( name=TDC )

within a R session and I get 


Creating directories ...
Creating DESCRIPTION ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './TDC/Read-and-delete-me'.
Warning messages:
1: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
2: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
3: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse of an S4 object will not be source()able
4: In dump(internalObjs, file = file.path(code_dir,
sprintf(%s-internal.R,  :
  deparse may be incomplete


I keep going in spite of the warnings with 
R CMD check --no-examples TDC


and I get 
* checking for working pdflatex ... OK

* using log directory
'/home/mariepierre/Packages/PermAlgo/PermAlgo/PermAlgo2/TDC.Rcheck'
* using R version 2.7.1 (2008-06-23)
* using session charset: UTF-8
* checking for file 'TDC/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'TDC' version '1.0'
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking whether package 'TDC' can be installed ... ERROR
Installation failed.

The error file says:
 
* Installing *source* package 'TDC' ...

** R
** preparing package for lazy loading
Error in parse(n = -1, file = file) : unexpected '' at
102: `.__C__BindArgs` -
103: 
Calls: Anonymous - code2LazyLoadDB - sys.source - parse
Execution halted
ERROR: lazy loading failed for package 'TDC'
** Removing
'/home/mariepierre/Packages/PermAlgo/PermAlgo/PermAlgo2/TDC.Rcheck/TDC'

The problem is with my classes and methods. The respective files contain:

setClass(BindArgs,  signature( function ))
setClass(BindArgs2, signature( function )) 


and

setMethod(initialize, BindArgs, function( .Object, f, ... )
  callNextMethod( .Object, function( x ) f( x, ... ) )) 


setMethod(initialize, BindArgs2, function( .Object, f, ...)
  callNextMethod( .Object, function( x, y ) f( x, y, ... ) )) 


Everything works well within a R session but I can build the package.

If I look at the internal R file that this created I get

`.__C__BindArgs` -
S4 object of class structure(classRepresentation, package = methods)
`.__C__BindArgs2` -
S4 object of class structure(classRepresentation, package = methods)
`.__M__initialize:methods` -
S4 object of class structure(MethodsList, package = methods)
`.__T__initialize:methods` -
environment

Well, let just say that I am new to classes so this confuses me greatly. I
have checked the documentation and tried a few things but I reached my
personal limits!

I am using R 2.7.1 on Linux Fedora 8.

Any comments on what is happening and/or help would be greatly appreciated.

  
The main point is that you should not rely on R putting sensible code in 
the package source files, but rather stay in control yourself. What the 
warnings are telling you is that you cannot deparse an S4 object in a 
way that can be reparsed, so dump() doesn't work. What you get is


obj -  S4 object..

and the syntax error from source() if you try using it. So what you need 
to is to delete it and put in the appropriate class/methods definitions 
from your original sources. It might help to look at an existing 
S4-using package.


--
  O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.