Code Monkey home page Code Monkey logo

argumentcheck's People

Contributors

nutterb avatar

Watchers

 avatar  avatar  avatar

argumentcheck's Issues

`match.arg` type method

It wouldn't hurt to have a match.arg method that wouldn't invoke stop, but I'm not sure if this would work with the case where only one may be used. If there is a failure to match, which option do I use to proceed with the checks?

finishArgCheck needs an `allComplete` argument

Or something similar.

It should append the error messages with the text "Function was terminated before all argument checks were complete"

That way I'm at least warning the user that I haven't checked all of their arguments before exiting, indicating the when they correct the current errors, there may be more to come.

The big instance I have in mind is with arguments that are missing. It would be a lot easier to check for all of the missing arguments and terminate when one is found than to have to work in logic of what to do in case of a missing argument. But it's also nice to let the user know that there may be more errors coming.

TRUE or FALSE...that is the question

This is a style thing, but I would tend to want the expr argument to evaluate to FALSE in order for addError() and addWarning() to append a message to the argcheck object. Because we're "checking" arguments to meet certain logical expressions.

(Not) Evaluating Logical Expressions with addError() and addWarning()

Sometimes we don't necessarily wish to evaluate a logical expression in our error messaging. Other times we want to both evaluate a logical expression and do some other stuff while checking.

JSD <- function(data, gp){
  ck <- ArgumentCheck::newArgCheck()
  ck <- ArgumentCheck::addError(is.data.frame(data), "'data' must be a data frame", ck)
  ck <- ArgumentCheck::addError(length(intersect(class(gp),c("character","factor")))>0,
                                "'gp' must be either the name of a factor variable in 'data' or a factor",
                                ck)
  finishArgCheck(ck)
  n <- nrow(data)

  ##########################################################
  # Note that I had to evaluate 'length(gp)>1' twice here
  ##########################################################
  if(is.character(gp)){
    ck <- ArgumentCheck::addWarning(length(gp)>1,
                                    "'gp' is a character vector of length >1. Using only the first element",
                                    ck)
    if(length(gp)>1) gp <- gp[1]
  }
  else if(is.factor(gp)){
    ck <- ArgumentCheck::addError(length(gp) == n,
                                  "factor 'gp' must have same length as number of rows in 'data'",
                                  ck)
  }
  ##########################################################
  # Note that I had to evaluate 'TRUE' here. 
  # Maybe making 'expr' an optional parameter would be good.
  # Or...what about setting 'expr=TRUE" by default?
  ##########################################################
  else Check <- ArgumentCheck::addError(TRUE,
                                        msg = "'gp' must be a numeric array",
                                        argcheck = Check)

}

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.