R/checkFuncArgs.R

Defines functions checkFuncArgs

Documented in checkFuncArgs

### check of any of the args to the function that calls 'func'
### match arguments of 'func'
### 
checkFuncArgs <- function( func, checkArgs, argName, funcName ) {
   ## is the 'func' a function?
   if( !is.function( func ) ) {
      stop( "argument '", argName, "' of function '", funcName,
         "' is not a function" )
   }

   funcArgs <- names( formals( func ) )

   if( length( funcArgs ) > 1 ) {
      a <- charmatch( funcArgs[ -1 ], checkArgs )
      if( sum( !is.na( a ) ) == 1 ) {
         stop( "argument '", funcArgs[ -1 ][ !is.na( a ) ],
            "' of the function specified in argument '", argName,
            "' of function '", funcName,
            "' (partially) matches the argument names of function '",
            funcName, "'. Please change the name of this argument" )
      } else if( sum( !is.na( a ) ) > 1 ) {
         stop( "arguments '",
            paste( funcArgs[ -1 ][ !is.na( a ) ], collapse = "', '" ),
            "' of the function specified in argument '", argName,
            "' of function '", funcName,
            "' (partially) match the argument names of function '",
            funcName, "'. Please change the names of these arguments" )
      }
   }
   return( NULL )
}

Try the maxLik package in your browser

Any scripts or data that you put into this service are public.

maxLik documentation built on May 29, 2024, 2:32 a.m.