@@ -243,7 +243,7 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
243243 where = where
244244 )
245245
246- classDef <- methods :: getClass( clname )
246+ classDef <- generator $ def
247247 # # non-public (static) fields in class representation
248248 # # <fixme> Should these become real fields? </fixme>
249249 fields <- classDef @ fieldPrototypes
@@ -270,7 +270,7 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
270270 } # #nocov end
271271
272272 # promoting show to S4
273- if ( any( grepl( " show" , names(CLASS @ methods ) ) ) ){
273+ if ( " show" %in% names(CLASS @ methods ) ){
274274 setMethod ( "show ", clname, function(object) object$show(), where = where ) # #nocov
275275 }
276276
@@ -304,24 +304,21 @@ Module <- function( module, PACKAGE = methods::getPackageName(where), where = to
304304 functions <- .Call( Module__functions_names , xp )
305305 for ( fun in functions ){
306306 storage [[ fun ]] <- .get_Module_function( module , fun , xp )
307-
308- # register as(FROM, TO) methods
309- converter_rx <- " ^[.]___converter___(.*)___(.*)$"
310- if ( length( matches <- grep( converter_rx , functions ) ) ){ # #nocov start
311- for ( i in matches ){
312- fun <- function s [i ]
313- from <- sub( converter_rx , " \\ 1" , fun )
314- to <- sub( converter_rx , " \\ 2" , fun )
315- converter <- function ( from ){}
316- body( converter ) <- substitute( { CONVERT(from ) },
317- list ( CONVERT = storage [[fun ]] )
318- )
319- setAs( from , to , converter , where = where )
320- }
321- } # #nocov end
322-
323307 }
324308
309+ # register as(FROM, TO) methods once storage holds every function: the
310+ # converter body captures storage[[fun]] by value via substitute()
311+ converter_rx <- " ^[.]___converter___(.*)___(.*)$"
312+ for ( fun in grep( converter_rx , functions , value = TRUE ) ){ # #nocov start
313+ from <- sub( converter_rx , " \\ 1" , fun )
314+ to <- sub( converter_rx , " \\ 2" , fun )
315+ converter <- function ( from ){}
316+ body( converter ) <- substitute( { CONVERT(from ) },
317+ list ( CONVERT = storage [[fun ]] )
318+ )
319+ setAs( from , to , converter , where = where )
320+ } # #nocov end
321+
325322 assign( " storage" , storage , envir = as.environment(module ) )
326323 module
327324}
0 commit comments