PBSmodelling (version 2.68.8)

evalCall: Evaluate a Function Call

Description

Evaluates a function call after resolving potential argument conflicts.

Usage

evalCall(fn, argu, ..., envir = parent.frame(),
    checkdef=FALSE, checkpar=FALSE)

Value

Invisibly returns the string expression of the function call that is passed to eval(parse(text=expr)).

Arguments

fn

R function

argu

list of explicitly named arguments and their values to pass to fn.

...

additional arguments that a user might wish to pass to fn.

envir

environment from which the call originates (currently has no use or effect).

checkdef

logical: if TRUE, gather additional formal arguments from the functions default function.

checkpar

logical: if TRUE, gather additional graphical arguments from the list object par.

Author

Rowan Haigh, Pacific Biological Station, Fisheries and Oceans Canada, Nanaimo BC

Details

This function builds a call to the specified function and executes it. During the build, optional arguments (...) are checked for
(i) duplication with explicit arguments argu: if any are duplicated, the user-supplied arguments supersede the explicit ones;
(ii) availability as usable arguments in fn, fn.default if checkdef=TRUE, and par if checkpar=TRUE.

See Also

doAction, plotAsp

Examples

Run this code
local(envir=.PBSmodEnv,expr={
  oldpar = par(no.readonly=TRUE)
  # A user may have a function that calls other functions
  # using specific defaults (e.g., blue triangles)
  #------------------------------------------------------
  pbsfun = function(..., use.evalCall=TRUE) {
    plotAsp(0,0,type="n",xlim=c(-1.5,1.5),ylim=c(-1.5,1.5),
      axes=FALSE, frame.plot=TRUE, xlab="",ylab="")
    if (use.evalCall)
      evalCall(polygon, ...,
        argu=list(x=c(-1,1,0),y=c(1,1,-1), col="dodgerblue", border="grey"))
    else
      polygon(x=c(-1,1,0),y=c(1,1,-1),col="dodgerblue",border="grey",...) 
  }
  par(mfrow=c(2,1))
  pbsfun(lwd=4,use.evalCall=FALSE)
  #------------------------------------------------------
  # But what if the user wants pink triangles?
  pbsfun(col="pink",lwd=4,use.evalCall=TRUE,checkpar=TRUE)
  par(oldpar)
})

# Without 'evalCall' an error occurs due to duplicated arguments
if (FALSE) pbsfun(col="pink",lwd=4,use.evalCall=FALSE)

Run the code above in your browser using DataLab