[Rcpp-devel] namespace trick required

Romain Francois romain at r-enthusiasts.com
Thu Nov 25 11:17:07 CET 2010


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 ?

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/9VOd3l : ZAT! 2010
|- http://bit.ly/c6DzuX : Impressionnism with R
`- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube




More information about the Rcpp-devel mailing list