How to build a dendrogram from a directory tree?

后端 未结 3 567
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 18:05

Given a root absolute directory path. How do I generate a dendrogram object of all path\'s below it so that I can visualize the directory tree with R?

Suppose the fo

3条回答
  •  旧巷少年郎
    2020-12-23 18:18

    If you are on Windows, you can use my package dir2json, by installing it like this:

    drat::addRepo("stlarepo")
    install.packages("dir2json")
    

    It is also possible to use it on Linux, but there is a DLL linked to the GHC dynamic libraries, which must be installed on the system (while this DLL is standalone on Windows).

    > library(dir2json)
    > cat(dir2tree("src"))
    src
    |
    `- contrib
       |
       +- PACKAGES.gz
       |
       +- PACKAGES
       |
       +- jsonAccess_0.1.1.tar.gz
       |
       +- expansions_1.2.tar.gz
       |
       `- dir2json_2.1.0.tar.gz
    > cat(dir2tree("src", vertical=TRUE))
                                                src                                             
                                                 |                                              
                                              contrib                                           
                                                 |                                              
          ---------------------------------------------------------------------------           
         /          |                 |                       |                      \          
    PACKAGES.gz  PACKAGES  jsonAccess_0.1.1.tar.gz  expansions_1.2.tar.gz  dir2json_2.1.0.tar.gz
    

    The package also contains a Shiny application which generates an interactive Reingold-Tilford tree representation of a folder:

    > dir2json::shinyDirTree(".")
    

提交回复
热议问题