Git Product home page Git Product logo

werner's Introduction

werner: Improve R package quality by mapping it.

Build Status Coverage Status

Installing werner

To install the latest development release of werner, please ensure that you are running version 3.3 or later of R and run the following code:

install.packages("devtools")
devtools::install_github("aaronrudkin/werner")

Getting started

werner contains two main functions.

explore_package returns a list of connections between functions:

library(werner)
explore_package("werner")

adjacency_matrix returns an adjacency matrix (by default a sparse matrix from the Matrix package, optionally a base R matrix object.)

library(werner)
adjacency_matrix("werner") # Sparse matrix
adjacency_matrix("werner", coerce_to_matrix=TRUE) # Base R matrix.

These adjacency matrices can be fed to igraph or other graphing packages in R.

Code Style

Code should adhere to the tidyverse style guide, with the exception of assignment operators, which should be the traditional "=" rather than the "<-" assignment. You can check code style by opening the package Rproj file and running:

library(goodpractice)
gp(checks = setdiff(all_checks(), "lintr_assignment_linter"))

werner's People

Contributors

aaronrudkin avatar

Stargazers

Andrew Allen Bruce avatar Neal Fultz avatar

Watchers

Neal Fultz avatar

werner's Issues

Function calls which are dynamic currently return INVALID

Functions which take function calls as arguments and then use those function calls later will currently flag INVALID:

MWE:

library(werner)
explore_package("base")$`base::outer`

FUN is an argument to outer which defaults to "*".

.Internal not supported

Currently, .Internal methods are not correctly supported; werner will find the function, be unable to namespace it (because it doesn't exist in any namespace).

MWE:

library(werner)
explore_package("base")$`base::readRDS`

Backtick reserved keywords

Trying to explore the base package will fail because werner will hit functions that are reserved keywords and fail to backtick them. I should add to the name quoter context for these.

The reserved keywords are:
"while", "repeat", "next", "if", "function", "for", and "break"

r_reserved_words.pdf

Functions defined inside functions not supported

Consider base::tryCatch:

function (expr, ..., finally) 
{
    tryCatchList <- function(expr, names, parentenv, handlers) {
        nh <- length(names)
        if (nh > 1L) 
            tryCatchOne(tryCatchList(expr, names[-nh], parentenv, 
                handlers[-nh]), names[nh], parentenv, handlers[[nh]])
        else if (nh == 1L) 
            tryCatchOne(expr, names, parentenv, handlers[[1L]])
        else expr
    }
    ...
    tryCatchList(expr, classes, parentenv, handlers)
}

It's obvious that tryCatchList is defined within the function. werner handles these improperly, returning INVALID namespace for the internal functions.

library(werner)

explore_package("base")$`base::tryCatch`

Unusual namespacing in utils? [Mitigated but not solved]

utils at some point creates an environment with the name tools.rstudio which at least one function call calls; this causes an error because of my strategy for finding functions by loading packages onto the namespace not working when the package in question isn't a package. I mitigated it by detecting it and ignoring it, but not totally sure if there's something else I should be doing here. Probably ephemeral to utils.

Functions allocated to variables within functions are not resolved

INVALID resolutions in base:

library(werner)
z = explore_package("base")
z$`base::unloadNamespace`

base::unloadNamespace resolves to:

function (ns) 
{
    if ((is.character(ns) && any(ns == loadedNamespaces())) || 
        (is.environment(ns) && any(getNamespaceName(ns) == loadedNamespaces()))) {
        runHook <- function(hookname, env, ...) {
            if (!is.null(fun <- env[[hookname]])) {
                res <- tryCatch(fun(...), error = identity)
                if (inherits(res, "error")) {
                  warning(gettextf("%s failed in %s() for '%s', details:\n  call: %s\n  error: %s", 
                    hookname, "unloadNamespace", nsname, deparse(conditionCall(res))[1L], 
                    conditionMessage(res)), call. = FALSE, domain = NA)
                }
            }
        }
  ...
}

The fun() call is obviously defined inside the function.

igraph - map size of nodes to LoC

It would be slick if long functions were larger and short functions were smaller. LoC is one measure, out degree would be another.

apply call functions not properly recorded

I believe that calls from one function to another via a *apply function are not being recorded, possibly because the function is resolving as a symbol rather than a language call, so it's not being picked up?

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.