[R] name of object

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Nov 14 14:15:59 CET 2005


On Mon, 14 Nov 2005, Claus Atzenbeck wrote:

> Hi,
>
> I have the following function:
>
>    test <- function(x)
>    {
>        print(shapiro.test(x))
>        ...
>    }
>
> The output for "test(sample1$sec)" is:
>
>    Shapiro-Wilk normality test
>
>    data:  x
>    W = 0.9447, p-value = 0.5767
>    ...
>
> I would like to see "data: sample1$sec" instead of "data: x", as it
> would be when directly called "shapiro.test(sample1$sec)".
>
> How can I do that? I browsed the documentation and other literature, but
> did not find any solution.

Use substitute().  Something like

test <- function(x)
{
    xlab <- substitute(x)
    print(eval.parent(substitute(shapiro.test(x), list(x=xlab))))
}

See S Programming section 3.5.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list