Generating a Call Graph in R

前端 未结 4 1615
天涯浪人
天涯浪人 2020-12-02 20:39

I\'ve been given a big chunk of poorly formatted monolithic R code with plenty of functions, and I\'d like to work out what functions call what functions.

I thought

4条回答
  •  不思量自难忘°
    2020-12-02 20:48

    Would profr help you out? From the documentation:

    > ?profr
    > glm_ex <- profr(example(glm))
    Read 17 items
    >      head(glm_ex)
                 f level time start  end  leaf source
    8      example     1 0.32  0.00 0.32 FALSE  utils
    9       2 0.04  0.00 0.04 FALSE   
    10      source     2 0.28  0.04 0.32 FALSE   base
    11  prepare_Rd     3 0.02  0.00 0.02 FALSE   
    12      render     3 0.02  0.02 0.04 FALSE   
    13 getSrcLines     3 0.02  0.04 0.06 FALSE   base
    >      summary(glm_ex)
                   f          level             time          start       
     eval.with.vis  :10   Min.   : 1.000   Min.   :0.02   Min.   :0.0000  
         : 3   1st Qu.: 4.000   1st Qu.:0.02   1st Qu.:0.1200  
     lazyLoadDBfetch: 3   Median : 6.000   Median :0.02   Median :0.2000  
     %in%           : 3   Mean   : 7.211   Mean   :0.03   Mean   :0.1769  
     inherits       : 3   3rd Qu.: 9.000   3rd Qu.:0.02   3rd Qu.:0.2600  
     is.factor      : 3   Max.   :22.000   Max.   :0.32   Max.   :0.3000  
     (Other)        :65                                                   
          end            leaf            source         
     Min.   :0.0200   Mode :logical   Length:90         
     1st Qu.:0.1500   FALSE:75        Class :character  
     Median :0.2400   TRUE :15        Mode  :character  
     Mean   :0.2069   NA's :0                           
     3rd Qu.:0.2800                                     
     Max.   :0.3200                                     
    
    > plot(glm_ex)
    

    enter image description here

    Not quite what you are after, but you may be able to adapt it to your needs.

提交回复
热议问题