It is not really an argument to mmatplot; it is an argument to mapply and I
am not certain what might be happening in there with respect to lazy
evaluation. Yes you can set it up with lapply, but I don't think speed is a
concern since most of the time is being spent in the matplot routine. If
you are really concerned, use system.time to check out the difference.
lapply would probably look like:
lapply(1:ncol(A), function(x) mmatplot(x, 1:nrow(A), A, main=paste("Array
input, column", x)))
but I would guess you would not see any difference unless you were plotting
10,000 columns and then the difference would be small.
On 3/4/07, Thaden, John J <[EMAIL PROTECTED]> wrote:
>
> Apparently you're right that colnum doesn't exist when it needs to
> be evaluated, but why? Why is 'paste' being evaluated so early? It is,
> after all, the value of an argument ('main') of my mmatplot function
> with colnum being another argument. I thought arguments were lazy-loaded.
> Does using mapply change the rules?
>
> Is there a way (like mapply) to loop at some lower level rather than
> Explicitly, in the R script, as in your suggestion? For speed's sake?
>
> Thanks. -John
>
>
> On Sunday Mar 4 2007, jim holtman <[EMAIL PROTECTED]> replied
>
> > First of all, 'colnum' does not exist when the 'paste' is called.
> > This probably does what you want:
>
> > for (colnum in 1:ncol(A)){
> > mmatplot(colnum, 1:nrow(A), A, main=paste("Array input, column",
> colnum))
> > }
>
>
> On 3/4/07, John Thaden <[EMAIL PROTECTED]> wrote:
> Hello, the code below is supposed to be a wrapper for matplot to
> do columnwise visible comparison of several matrices, but I'm
> doing something wrong because I can't access an argument called
> 'colnum'.I'd be most grateful for some insight.
>
> Thanks,
> John
> Little Rock, AR
> ################################
> # mmatplot is a matplot wrapper to compare the same column of
> # several matrices. Arg y is either a list of matrices with
> # equal number of rows, or an array. The scalar n gives the
> # column of each matrix or array slab to plot. par values and
> # matplot args are accepted, e.g., ylog.mmatplot is intended
> # to be mapply-compatible to test multiple columns.
>
> mmatplot <- function(colnum, x, y, ...){
> switch(class(y),
> array = y <- y[, colnum, ],
> list = y <- sapply(X = y, FUN = subset, select = colnum))
> stopifnot(is.matrix(y))
> matplot(x, y, ...)
> }
>
> #This is just a tester function
> mmatplotTest <- function(){
> oldmf <- par("mfrow")
> par(mfrow = c(2,3))
> A <- array(data = rnorm(90), dim = c(10, 3, 3))
> L <- list(A[, , 1], A[, , 2], A[, , 3])
>
> # The 'main' argument below throws the error, but if
> # commented out, another error crops up due to 'colnum'.
> # Test with class(y) == "array"
> mapply(X = 1:ncol(A), FUN = mmatplot, x = 1:nrow(A), y = A,
> main = paste("Array input, column", colnum))
> # Test with class(y) == "list"
> mapply(1:ncol(L[[1]]), mmatplot, x = 1:nrow(L[[1]]), y = L,
> main = paste("List input, column", colnum))
> par(mfrow = oldmf)
> }
>
> #Run the test
> mmatplotTest()
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
> Confidentiality Notice: This e-mail message, including any attachments, is
> for the sole use of the intended recipient(s) and may contain confidential
> and privileged information. Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply e-mail and destroy all copies of the original
> message.
>
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.