├── .gitignore ├── data ├── dplyr ├── forcats ├── ggplot2 ├── purrr ├── readr ├── stringr ├── tibble └── tidyr ├── packageexplorer.Rproj ├── README.md ├── scripts.R ├── rsconnect └── shinyapps.io │ └── joycerobbins │ └── packageexplorer.dcf ├── create_package_igraph.R └── app.R /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /data/dplyr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/dplyr -------------------------------------------------------------------------------- /data/forcats: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/forcats -------------------------------------------------------------------------------- /data/ggplot2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/ggplot2 -------------------------------------------------------------------------------- /data/purrr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/purrr -------------------------------------------------------------------------------- /data/readr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/readr -------------------------------------------------------------------------------- /data/stringr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/stringr -------------------------------------------------------------------------------- /data/tibble: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/tibble -------------------------------------------------------------------------------- /data/tidyr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtr13/packageexplorer/master/data/tidyr -------------------------------------------------------------------------------- /packageexplorer.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: XeLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # packageexplorer 2 | 3 | This repo contains the code for a shiny app to explore tidyverse function dependencies: https://joycerobbins.shinyapps.io/packageexplorer/ 4 | 5 | The shiny app makes use of the [rOpenSci](https://ropensci.org/) [pkginspector](https://github.com/ropenscilabs/pkginspector/) package to map and then visualize these dependencies. 6 | -------------------------------------------------------------------------------- /scripts.R: -------------------------------------------------------------------------------- 1 | # script to create igraph data needed for visualizations 2 | 3 | source("create_package_igraph.R") 4 | 5 | # set package name here: 6 | pkgname <- "tidyr" 7 | 8 | pkginfo <- download.packages(pkgname, tempdir()) 9 | 10 | untar(pkginfo[2], exdir = tempdir()) 11 | 12 | pkgigraph <- create_package_igraph(file.path(tempdir(),pkginfo[1]), external = TRUE) 13 | 14 | saveRDS(pkgigraph, file.path("data", pkginfo[1])) 15 | 16 | -------------------------------------------------------------------------------- /rsconnect/shinyapps.io/joycerobbins/packageexplorer.dcf: -------------------------------------------------------------------------------- 1 | name: packageexplorer 2 | title: packageexplorer 3 | username: 4 | account: joycerobbins 5 | server: shinyapps.io 6 | hostUrl: https://api.shinyapps.io/v1 7 | appId: 380998 8 | bundleId: 1815731 9 | url: https://joycerobbins.shinyapps.io/packageexplorer/ 10 | when: 1547569531.27858 11 | asMultiple: FALSE 12 | asStatic: FALSE 13 | ignoredFiles: create_package_igraph.R|README.md|scripts.R 14 | -------------------------------------------------------------------------------- /create_package_igraph.R: -------------------------------------------------------------------------------- 1 | create_package_igraph <- function(path = ".", include_base = FALSE, directed = TRUE, external = FALSE) { 2 | mapped <- functionMap::map_r_package(path = path, include_base = include_base) 3 | 4 | # remove external functions if external == FALSE 5 | if (external) { 6 | node_df <- mapped$node_df 7 | } else { 8 | node_df <- mapped$node_df[mapped$node_df$own == TRUE, ] 9 | } 10 | 11 | # remove duplicate vertices 12 | 13 | node_df <- node_df[!duplicated(node_df$ID), ] 14 | 15 | # remove "_" which often appears as a vertex 16 | 17 | node_df <- node_df[node_df$ID != "_", ] 18 | 19 | # order vertices by ID (useful for selecting nodes) 20 | 21 | node_df <- node_df[order(node_df$ID), ] 22 | 23 | # verify that "to" vertices are in node list 24 | edge_df <- mapped$edge_df[mapped$edge_df$to %in% node_df$ID, ] 25 | 26 | # verify that "from" vertices are in node list 27 | edge_df <- edge_df[edge_df$from %in% node_df$ID, ] 28 | 29 | # eliminate duplicate edges 30 | edge_df <- edge_df[!duplicated(edge_df[, c("from", "to")]), ] 31 | 32 | igraph_obj <- igraph::graph_from_data_frame(edge_df, directed = directed, vertices = node_df) 33 | 34 | igraph::set_vertex_attr(igraph_obj, "exported", value = node_df$exported) 35 | } 36 | -------------------------------------------------------------------------------- /app.R: -------------------------------------------------------------------------------- 1 | library(shiny) 2 | library(visNetwork) 3 | 4 | pkgs <- list.files("data") 5 | igraphs <- lapply(file.path("data", pkgs), readRDS) 6 | 7 | ui <- fluidPage( 8 | 9 | sidebarLayout( 10 | 11 | sidebarPanel( 12 | 13 | selectInput("pkgname", label = "Choose package:", choices = pkgs), 14 | br(), 15 | br(), 16 | 17 | checkboxInput("freeze", "Freeze non-selected nodes", TRUE), 18 | 19 | checkboxInput("external", "Include external functions", FALSE), 20 | 21 | conditionalPanel(condition = "input.freeze == false", 22 | sliderInput("centralGravity", 23 | "centralGravity:", 24 | min = 0, 25 | max = 1, 26 | value = .3) 27 | ), 28 | 29 | h4("Notes: "), 30 | p("* IT'S ALL ABOUT THE SUBGRAPHS: Zoom/pan and then hover or click a node--or choose a function from the dropdown box--to see reverse function dependencies for that function only."), 31 | p("* TO SAVE IMAGE: Right click while hovering on selected node."), 32 | p("* CAVEAT: Misses functions called in purrr::map statements and similar (to be fixed)"), 33 | span("* For more info on rendering function, see:"), 34 | a("http://rpubs.com/jtr13/vis_package", href = "http://rpubs.com/jtr13/vis_package", target = "_blank"), br(), br(), 35 | span("* Source code:"), 36 | a("http://www.github.com/jtr13/packageexplorer", href = "http://www.github.com/jtr13/packageexplorer", target = "_blank"), 37 | p(" "), 38 | p("* To improve speed, tidyverse package info is stored. Last update: Jan. 15, 2019") 39 | 40 | ), 41 | 42 | mainPanel( 43 | 44 | titlePanel("Tidyverse Function Dependency Explorer"), 45 | 46 | verbatimTextOutput('directorypath'), 47 | 48 | visNetworkOutput("network") 49 | ) 50 | ) 51 | ) 52 | 53 | server <- function(input, output) { 54 | 55 | ## render the network diagram 56 | output$network <- renderVisNetwork({ 57 | i <- which(pkgs == input$pkgname) 58 | pkginspector::vis_package(igraph_obj = igraphs[[i]], 59 | physics = !input$freeze, 60 | external = input$external, 61 | centralGravity = input$centralGravity, 62 | icons = FALSE) 63 | }) 64 | } 65 | 66 | # Run the application 67 | shinyApp(ui = ui, server = server) 68 | 69 | --------------------------------------------------------------------------------