[BioC] function within a function body?

Robert Gentleman rgentlem at jimmy.harvard.edu
Fri May 16 11:03:28 MEST 2003


Hi,
  Functions do not have to have names. The name is merely a symbol
  that is used to identify and manipulate the function, but you can
  (and we often do) have anonymous functions.

   For example:
     (function(x,y){x+y})(4,6)

  if you type this at the R prompt you will get the value 10
  returned. The value of x is 4, of y is 6. The first statement (in
  parentheses) defines a function. The second set of parentheses
  indicated that you want to apply that function to the arguments
  given (4 and 6).

   There are a number of resources on S language programming available
   to help with understanding the language (some free, others not).

  Robert

On Fri, May 16, 2003 at 09:48:38AM -0400, SHEN, WEICHENG . wrote:
> 
> Hi all:
> 
> In studying the code for bioconductor, I found something that I don't
> understand. The function implementation that I can not understand is
> "maLowessLines." The function is listed below. The syntex that I don't
> understand is "function(x, y, z)". It appears that this is a function within
> a function (maLowessLines). What is the name of this function? Where does it
> get the values of x, y, z? Any hints and suggestions will be greatly
> appreciated. Thanks!
> 
> ============================================================================
> ===================================
> 
> 
> maLowessLines <- function (subset = TRUE, f = 0.3, col = 2, lty = 1, lwd =
> 2.5, 
>     ...) 
> {
>     function(x, y, z) {
>         subset <- maNum2Logic(length(x), subset)
>         g <- unique(z[subset])
>         if (length(col) < length(g)) 
>             col <- rep(col[1], length(g))
>         if (length(lty) < length(g)) 
>             lty <- rep(lty[1], length(g))
>         for (i in (1:length(g))) {
>             which <- z[subset] == g[i]
>             xx <- x[subset][which]
>             yy <- y[subset][which]
>             ind <- is.na(xx) | is.na(yy) | is.infinite(xx) | 
>                 is.infinite(yy)
>             fit <- lowess(xx[!ind], yy[!ind], f = f)
>             lines(fit, col = col[i], lty = lty[i], lwd = lwd, 
>                 ...)
>         }
>     }
> }
> 
> Weicheng Shen, Ph.D.
> Senior Image Analyst
> Science Applications International Corporation
> 1710 SAIC Drive
> Mail Stop 2-6-9
> McLean, VA 22102
> (703) 676-4189
> 
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/bioconductor

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: M1B20                            |
| Harvard School of Public Health  email: rgentlem at jimmy.harvard.edu        |
+---------------------------------------------------------------------------+



More information about the Bioconductor mailing list