[R] Calling Function With Arguments In a Script

Rich Shepard rshepard at appl-ecosys.com
Thu May 7 22:50:33 CEST 2015


   I'm starting to put code in multi-use functions rather than in individual
scripts and have not learned how to invoke the function from the command
line. If this information is in Norman Matloff's 'The Art of R Programming'
or Hadley Wickham's 'Advanced R' please point me to the proper place.

   Here's an example, the script 'pairwise-plots-continuous-vars.R' consists
of this function:

plotpairs <- function(x1,x2,x3,y,plotmain) {
     require(compositions)
     opar <- par(mar=c(4,4,3,1))
     NO3 <- x1
     SO4 <- x2
     pH <- x3
     pairwisePlot(cbind(NO3,SO4,pH),clr(y),add.line=T)
     title(main=plotmain)
     par(opar)
     detach('package:compositions')
     return()
}

   (I suppose the return statement is superfluous since there is no value
returned to a calling function.)

   What I want to do is call plotpairs() with appropriate arguments for each
plot as needed.

TIA,

Rich



More information about the R-help mailing list