Code Monkey home page Code Monkey logo

packagestructure's Introduction

packagestructure

Create a graph of the structure of an R package.

May be useful in reducing the cognitive load when writing R packages with any more than a few S4 classes.

Currently only supports S4 classes and slots. See TODO list below.

Installation

devtools::install_github("rmflight/packagestructure")

Examples

A Source Package on Your Local Machine

library(packagestructure)
example_package <- system.file("exampledata", package = "packagestructure")
e_g <- class_graph(example_package)
plot(e_g)

plot of chunk unnamed-chunk-1

In this example, classes class_B, class_C directly inherit from class_A, while class_D inherits from class_B. Each of these has particular slots of particular classes. You can see the set of class definitions here.

An Installed Package

# not run
library(Matrix)
m_g <- class_graph("package:Matrix")
plot(m_g)

History

Another package, classGraph is available on Cran, and was created by Martin Maechler based on code originally done by Robert Gentleman. However, that package uses Bioconductor's graph package (which does not handle graph unions nicely), and Rgraphviz, which can be a pain to install on Windows machines, and does not handle slots and their relationships.

Therefore I used some of the relevant code from Martin's package (licensed as GPL, which is why this package is GPL-2 and why he is listed as an author), converted it to use igraph, and did some of my own thing.

TODO

  • improve test coverage (classunion and no-classes)
  • add travis-ci and coveralls
  • allow specification of classes to show and classes to exclude
  • add methods?
  • add function call dependency?

packagestructure's People

Contributors

rmflight avatar

Stargazers

 avatar DL Miller avatar

Watchers

James Cloos avatar  avatar

packagestructure's Issues

switch to igraph

Should we be using the igraph packge instead of graph? It provides automatic plotting, and if we need the graphNEL for viewing in Cytoscape, etc, we should be able to convert w/out too much trouble.

use changed envir to test package:pkgname

Check if getting the package environment modifies the search(), and is stable between tests so that we can just use the changed envir to do the package:pkgname test instead of actually doing load_all()

multiclass version of classtree

classGraph package has class tree function to generate tree for one class. We should be able to generate multiple trees and merge them

custom join function

Need a custom join function that handles nodes with no edges, and duplicate edges.

The current join will choke on duplicate edges and nodes with no edges.

remove inherited slots

With the full slot class tree in #2, there may be redundancy in the slots. We should only keep slots that are unique to a class when we have class inheritance.

I think only way to do this is for each leaf, generate list of slots:classes, and for each parent of leaf, remove slots:classes that exist in the leaves. May be difficult to keep list of slot:classes updated correctly so that wrong slots don't get removed on the wrong parent. Will take work to design the right test cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.