Le 25/11/10 11:17, Romain Francois a ?crit :
Hello,
With formals<- I added into Rcpp yesterday, I have updated the parser
package as such:
NAMESPACE <- environment()
MODULE <- Module( "parser_module" )
nlines <- function( file ) NULL
count.chars <- function( file, encoding = "unknown" ) NULL
.onLoad <- function( libname, pkgname ){
unlockBinding( "nlines" , NAMESPACE )
unlockBinding( "count.chars" , NAMESPACE )
nlines <- MODULE$nlines
formals( nlines ) <- alist( file = )
assign( "nlines", nlines, NAMESPACE )
count.chars <- MODULE$count.chars
formals( count.chars ) <- alist( file = , encoding = "unknown" )
assign( "count.chars", count.chars, NAMESPACE )
lockBinding( "nlines", NAMESPACE )
lockBinding( "count.chars", NAMESPACE )
}
This is somewhat annoying that we have to first create dummies for
"nlines" and "count.chars", and then hijack them on the .onLoad.
Can anyone think of another way ?
Ah. This is what happens when you send a message too early. We actually
don't need the dummies and can do:
NAMESPACE <- environment()
MODULE <- Module( "parser_module" )
.onLoad <- function( libname, pkgname ){
nlines <- MODULE$nlines
formals( nlines ) <- alist( file = )
assign( "nlines", nlines, NAMESPACE )
count.chars <- MODULE$count.chars
formals( count.chars ) <- alist( file = , encoding = "unknown" )
assign( "count.chars", count.chars, NAMESPACE )
lockBinding( "nlines", NAMESPACE )
lockBinding( "count.chars", NAMESPACE )
}
I'm thinking about :
- deal with the formals internally
- add an R function that would dump functions and classes from a module
into an environment or a namespace.