Error in heatmap.2 (gplots)

前端 未结 3 2041
一整个雨季
一整个雨季 2020-12-18 07:34

Ive moved on to a new server and Installed R version 3.0 on it. (gplots library was no longer available for 2.14)

Using a script that worked for version 2.14 I now e

3条回答
  •  生来不讨喜
    2020-12-18 08:25

    I'm the author of the gplots package. The 'node stack overflow' error occurs when a byte-compiled function has too many recursive calls.

    In this case, it occurs because the function that plots dendrogram objects (stats:::plotNode) is implemented using a recursive algorithm and the dendrogram object is deeply nested.

    Ultimately, the correct solution is to modify plotNode to use an iterative algorithm, which will prevent the recursion depth error from occuring.

    In the short term, it is possible to force stats:::plotNode to be run as interpreted code rather then byte-compiled code via a nasty hack.

    Here's the recipe:

    ## Convert a byte-compiled function to an interpreted-code function 
    unByteCode <- function(fun)
        {
            FUN <- eval(parse(text=deparse(fun)))
            environment(FUN) <- environment(fun)
            FUN
        }
    
    ## Replace function definition inside of a locked environment **HACK** 
    assignEdgewise <- function(name, env, value)
        {
            unlockBinding(name, env=env)
            assign( name, envir=env, value=value)
            lockBinding(name, env=env)
            invisible(value)
        }
    
    ## Replace byte-compiled function in a locked environment with an interpreted-code
    ## function
    unByteCodeAssign <- function(fun)
        {
            name <- gsub('^.*::+','', deparse(substitute(fun)))
            FUN <- unByteCode(fun)
            retval <- assignEdgewise(name=name,
                                     env=environment(FUN),
                                     value=FUN
                                     )
            invisible(retval)
        }
    
    ## Use the above functions to convert stats:::plotNode to interpreted-code:
    unByteCodeAssign(stats:::plotNode)
    
    ## Now raise the interpreted code recursion limit (you may need to adjust this,
    ##  decreasing if it uses to much memory, increasing if you get a recursion depth error ).
    options(expressions=5e4)
    
    ## heatmap.2 should now work properly 
    heatmap.2( ... )
    

提交回复
热议问题