[R] Help on a Display function

Hans W Borchers hwborchers at googlemail.com
Fri Jan 14 17:54:41 CET 2011

I wanted to simulate the Matlab DISPLAY function for some time now.
After seeing a recent proposal by Gabor Grothendieck I came up with the
following solution,

display <- function(...) {
  my_names  <- lapply(substitute(placeholderFunction(...))[-1], deparse)
  for (my in my_names) cat(my, "=", eval(parse(text=my)), "\n", sep=" ")

that works about as good as I would have hoped:

    > a <- 1; b <- a + 1
    > display(a, b, sin(1))
    a = 1 
    b = 2 
    sin(1) = 0.841471

My questions:

(1) Is there a better or more appropriate way to write such a function? ---
    I'm not so well versed in internal R functions such as (de)parse(),
    substitute(), or eval().

(2) What is the role of the "placeholderFunction"? I could not find enough
    information about it resp. about the whole construction.

Thanks, Hans Werner

More information about the R-help mailing list