After several months working on a given research project, the folder Given-Research-Project on your computer or on the server you share with your colleagues probably contains a lot of datasets, scripts, reports, graphs, articles, etc. At some point, you may want your internship supervisor or co-authors to be able to navigate smoothly into your folder, in case they want to consult one of your codes or results for instance. Directotree allows to represent the content of a directory as a dynamic and interactive collapsible tree with a single command. It offers the possibility to assign a description (e.g., the content of a Readme.txt) to each folder (represented as a clickable node), so that when the user hovers the pointer over a node, the corresponding text is displayed as a tooltip (the text could be a description of the content of the folder). For the sake of clarity the following examples were applied on a directory containing a few files only, but of course, the interest of the directotree command is for it to be used on folders with much denser contents.

Core arguments

library(directotree)
#By default, the size of a node is proportional to the number of elements it contains.
directotree('C:/Users/Louis/Given-Research-Project')

Even if the function can be used with all its default values as depicted above, it could be helpful to take advantage of its different features. For instance, the argument warnMe prints a warning message whenever an empty folder is detected, and reports its location. When showWd is set to TRUE, R will print each directory it goes into when navigating into your folder to build the tree. When something goes wrong, this can be of great help to identify where the problem comes from. Finally, instead of creating a collapsible tree, you can choose to simply print the tree structure in the console as follows (let’s do this on a subfolder for the output to be of a reasonable size).

directotree('C:/Users/Louis/Given-Research-Project/3. Literature', showWd = TRUE, warnMe = TRUE, showRawTree = TRUE, showCollapsibleTree = FALSE) 
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 1"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2/Part 2a"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2/Part 2b"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2/Part 2c"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 2"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature"
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature/Part 3"
## Warning in directotree("C:/Users/Louis/Given-Research-Project/3.
## Literature", : Empty folder detected: C:/Users/Louis/Given-Research-
## Project/3. Literature/Part 3
## [1] "C:/Users/Louis/Given-Research-Project/3. Literature"
##                         levelName
## 1  3. Literature                 
## 2   ¦--Part 1                    
## 3   ¦   ¦--Arts_2011.pdf         
## 4   ¦   ¦--Bäckström_2003.pdf    
## 5   ¦   ¦--Bäckström_2004.pdf    
## 6   ¦   ¦--Bass_1969.pdf         
## 7   ¦   ¦--Foxall_1986.pdf       
## 8   ¦   ¦--Foxall_1995.pdf       
## 9   ¦   °--Readme.txt            
## 10  ¦--Part 2                    
## 11  ¦   ¦--Part 2a               
## 12  ¦   ¦   ¦--Bonanno_2012.pdf  
## 13  ¦   ¦   ¦--Davis_2010.pdf    
## 14  ¦   ¦   °--DiGiacomo_2008.pdf
## 15  ¦   ¦--Part 2b               
## 16  ¦   ¦   ¦--Desai_2001.pdf    
## 17  ¦   ¦   ¦--DiGiacomo_2008.pdf
## 18  ¦   ¦   ¦--Frawley_2006.pdf  
## 19  ¦   ¦   °--Golder_1993.pdf   
## 20  ¦   ¦--Part 2c               
## 21  ¦   ¦   ¦--Bernardo_1976.pdf 
## 22  ¦   ¦   ¦--Herman_2003.pdf   
## 23  ¦   ¦   ¦--Lee_2000.pdf      
## 24  ¦   ¦   ¦--Mc_Dolby_2012.pdf 
## 25  ¦   ¦   ¦--Siermen_1999.pdf  
## 26  ¦   ¦   °--VanOlof_2016.pdf  
## 27  ¦   °--Readme.txt            
## 28  ¦--Part 3                    
## 29  °--Readme.txt

You can see from this output that the program does not dig vertically layer by layer into the folder, but that it visits each folder horizontally. Thanks to having set warnMe to TRUE, we now know that the folder “Part 3” is empty, and that it will thus displayed more like a leaf rather than like a node. It can be interesting to set showRawTree to TRUE instead of showCollapsibleTree if you need to store the tree structure for further use:

treeStructure <- directotree('C:/Users/Louis/Given-Research-Project/3. Literature', showWd = FALSE, warnMe = FALSE, showRawTree = TRUE, showCollapsibleTree = FALSE) 

print(treeStructure)
##                         levelName
## 1  3. Literature                 
## 2   ¦--Part 1                    
## 3   ¦   ¦--Arts_2011.pdf         
## 4   ¦   ¦--Bäckström_2003.pdf    
## 5   ¦   ¦--Bäckström_2004.pdf    
## 6   ¦   ¦--Bass_1969.pdf         
## 7   ¦   ¦--Foxall_1986.pdf       
## 8   ¦   ¦--Foxall_1995.pdf       
## 9   ¦   °--Readme.txt            
## 10  ¦--Part 2                    
## 11  ¦   ¦--Part 2a               
## 12  ¦   ¦   ¦--Bonanno_2012.pdf  
## 13  ¦   ¦   ¦--Davis_2010.pdf    
## 14  ¦   ¦   °--DiGiacomo_2008.pdf
## 15  ¦   ¦--Part 2b               
## 16  ¦   ¦   ¦--Desai_2001.pdf    
## 17  ¦   ¦   ¦--DiGiacomo_2008.pdf
## 18  ¦   ¦   ¦--Frawley_2006.pdf  
## 19  ¦   ¦   °--Golder_1993.pdf   
## 20  ¦   ¦--Part 2c               
## 21  ¦   ¦   ¦--Bernardo_1976.pdf 
## 22  ¦   ¦   ¦--Herman_2003.pdf   
## 23  ¦   ¦   ¦--Lee_2000.pdf      
## 24  ¦   ¦   ¦--Mc_Dolby_2012.pdf 
## 25  ¦   ¦   ¦--Siermen_1999.pdf  
## 26  ¦   ¦   °--VanOlof_2016.pdf  
## 27  ¦   °--Readme.txt            
## 28  ¦--Part 3                    
## 29  °--Readme.txt

Adding attributes

A great advantage of the directotree function is that you can easily assign a tooltip to each node that displays a description (or any other piece of information) of the corresponding folder. To do so, you need to set addReadme and tooltip to TRUE and to fill the attributeName argument with the name of your description file (it is case sensitive and it must include the extension of the file). As you may not want your description file to appear as a leaf in each folder of your tree, you can add its name hiddenFiles, a vector of strings that contains the names of all the files you do not want to be displayed in the tree.

directotree('C:/Users/Louis/Given-Research-Project', showWd = FALSE, warnMe = FALSE, showRawTree = FALSE, showCollapsibleTree = TRUE, tooltip = TRUE, addReadme = TRUE, attributeName = 'Readme.txt', hiddenFiles = c('Thumbs.db', 'Readme.txt')) 

Modifying style

Finally, directotree preserves the arguments of the collapsibleTree function that allow to modify the style of the tree. Here is an example, but more information is avaible in the collapsibleTree package description.

directotree('C:/Users/Louis/Given-Research-Project', showWd = FALSE, warnMe = FALSE, showRawTree = FALSE, showCollapsibleTree = TRUE, tooltip = TRUE, addReadme = TRUE, attributeName = 'Readme.txt', hiddenFiles = c('Thumbs.db', 'Readme.txt'), linkLength = 50, collapsed = FALSE, zoomable = TRUE, width = 800, height = 500, fontSize = 7, fill = 'green', nodeSize = 'count')