[R] pass nrow(x) to dots in function(x){plot(x,...)}

Marianne Promberger marianne.promberger at kcl.ac.uk
Wed Feb 2 12:51:50 CET 2011


Dear Rers,

I have a function to barplot() a matrix, eg

myfun <- function(x, ...) { barplot(x , ... )} 

(The real function is more complicated, it does things to the matrix first.)

So I can do:

m1 <-  matrix(1:20,4)
myfun(m1)
myfun(m1, main="My title")

I'd like to be able to add the number of rows of the matrix passed to
the function to the "..." argument, eg

myfun(m1, main=paste("n=",ns))

where 'ns' would be nrow(m1)

I've tried this but it doesn't work:

myfun <- function(x, ...) { 
      ns <- nrow(x)
      barplot(x , ... ) }

myfun(m1, main=paste("n = ",ns) )

ns is not found

So, basically, how do I assign an object inside a function that I can
then access in the dots when executing the function?

Many thanks

Marianne


-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.12.0 (2010-10-15)
Ubuntu 9.04



More information about the R-help mailing list