Skip to content
Prev 200865 / 398502 Next

Is there an variant of apply() that does not return anything?

On Nov 19, 2009, at 4:31 PM, Peng Yu wrote:

            
Here is one approach to give you some insight into how to get the name  
(as opposed to the object itself) of an argument passed to a function:

MyList <- list(a = 1, b = 2, e = 3)

PlotFn <- function(x)
{
   # Get the name of the object passed as 'x' (eg. "MyList")
   Main <- deparse(substitute(x))

   for (i in seq(along = x))
   {
     plot(x[[i]], main = Main, ylab = names(x[i]))
   }
}

# Set to pause between each graphic
par(ask = TRUE)

PlotFn(MyList)

Take note that the main title for each graphic will be "MyList" and  
the y axis label for each, will be the name of each of the three  
components in MyList (eg. "a", "b" and "e")

HTH,

Marc Schwartz