Re: [Rd] Possible problem with S4 dispatch
On Mon, 30 Apr 2007, Seth Falcon wrote: First a bit of disclaimer... I haven't isolated this problem into an easy to reproduce case, and I won't be surprised if the root cause is a fault in my code's use of name spaces or some such. Note that you called selectMethod(mget, signature(x=character, envir=class(LLe))) by name rather than calling the visible function mget() (which you could have supplied as fdef). I've never really got to the bottom of the complicated searches that getGeneric() uses, but the fact that it does not just look for a visible function of that name tells you it is doing something different. What I would check from your browser is what parent.env() shows, successively until you get to the imports and then the base namespace. If mget is not in the imports, something would seem to be up with your importing of namespaces. find() is not relevant here as namespace scoping is in play: only if the mget generic is imported will it take precedence over base:::mget. (It is not clear to me what is being browsed here, and hence what namespaces are in play.) Perhaps we need lexical versions of find() and search() to make it easier to explore search paths from a function body. Hope it helps: without a reproducible example I can only guess blindly. The error I'm seeing is one in which the desired method is not found. What worries me in terms of my expectations of how to debug the problem is that showMethods and selectMethod both find the method. Here is an example browser session: ## Input 1, a character vector Browse[1] gN[1:3] [1] 1005_at 1007_s_at 1008_f_at ## Input 2, an object of class AtomicAnnMap (subclass of AnnMap) Browse[1] class(LLe) [1] AtomicAnnMap attr(,package) [1] AnnotationDbi ## See what selectMethod has to say (it finds the method I'm expecting) Browse[1] selectMethod(mget, signature(x=character, envir=class(LLe))) Method Definition: function (x, envir, mode = any, ifnotfound = list(function(x) stop(paste(value for ', x, ' not found, sep = ), call. = FALSE)), inherits = FALSE) { .checkNamesAreStrings(x) .checkNamesExist(x, names(envir)) as.list(envir, names = x) } environment: namespace:AnnotationDbi Signatures: x envir target character AtomicAnnMap defined ANY AnnMap ## Call it (we get base::mget, not the generic and hence an error) Browse[1] mget(gN[1:3], LLe) Error in mget(x, envir, mode, ifnotfound, inherits) : second argument must be an environment Browse[1] find(mget) [1] package:AnnotationDbi package:base The package code I'm working with imports the package that defines the mget method (and this package does exportMethods(mget)), yet the problem seems to be that the mget generic is not found -- but I find it confusing that selectMethod works here. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Possible problem with S4 dispatch
Prof Brian Ripley [EMAIL PROTECTED] writes: Note that you called selectMethod(mget, signature(x=character, envir=class(LLe))) by name rather than calling the visible function mget() (which you could have supplied as fdef). I've never really got to the bottom of the complicated searches that getGeneric() uses, but the fact that it does not just look for a visible function of that name tells you it is doing something different. What I would check from your browser is what parent.env() shows, successively until you get to the imports and then the base namespace. If mget is not in the imports, something would seem to be up with your importing of namespaces. find() is not relevant here as namespace scoping is in play: only if the mget generic is imported will it take precedence over base:::mget. (It is not clear to me what is being browsed here, and hence what namespaces are in play.) This was helpful. It seems that the strange behavior I was seeing was due to stale package installations. After reinstalling the package and all of its depends and imports, things are looking more normal. I used the following function to examine the chain of parent environments while debugging: showEncEnvs - function() { etmp - parent.env(parent.frame()) while (TRUE) { ename - environmentName(etmp) cat(sprintf(Found envirnment: '%s'\n, ename)) if (exists(mget, etmp, inherits=FALSE)) cat(found mget\n) switch(ename, R_EmptyEnv=break, R_GlobalEnv=break) if (ename == ) { cat( first five entires\n) print(ls(etmp)[1:5]) } etmp - parent.env(etmp) } } One thing to note: One might expect each import to be in the chain of parent environments. Instead all imports are merged into a single environment that is the parent of the package env. + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Possible problem with S4 dispatch
Hi, First a bit of disclaimer... I haven't isolated this problem into an easy to reproduce case, and I won't be surprised if the root cause is a fault in my code's use of name spaces or some such. The error I'm seeing is one in which the desired method is not found. What worries me in terms of my expectations of how to debug the problem is that showMethods and selectMethod both find the method. Here is an example browser session: ## Input 1, a character vector Browse[1] gN[1:3] [1] 1005_at 1007_s_at 1008_f_at ## Input 2, an object of class AtomicAnnMap (subclass of AnnMap) Browse[1] class(LLe) [1] AtomicAnnMap attr(,package) [1] AnnotationDbi ## See what selectMethod has to say (it finds the method I'm expecting) Browse[1] selectMethod(mget, signature(x=character, envir=class(LLe))) Method Definition: function (x, envir, mode = any, ifnotfound = list(function(x) stop(paste(value for ', x, ' not found, sep = ), call. = FALSE)), inherits = FALSE) { .checkNamesAreStrings(x) .checkNamesExist(x, names(envir)) as.list(envir, names = x) } environment: namespace:AnnotationDbi Signatures: x envir target character AtomicAnnMap defined ANY AnnMap ## Call it (we get base::mget, not the generic and hence an error) Browse[1] mget(gN[1:3], LLe) Error in mget(x, envir, mode, ifnotfound, inherits) : second argument must be an environment Browse[1] find(mget) [1] package:AnnotationDbi package:base The package code I'm working with imports the package that defines the mget method (and this package does exportMethods(mget)), yet the problem seems to be that the mget generic is not found -- but I find it confusing that selectMethod works here. + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel