[R] Question about "evalq"
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon May 28 07:54:07 CEST 2007
How about 'traceback'? (It does not necesssarily show all the frames, but
it does help and the exceptions are fairly esoteric.)
On Mon, 28 May 2007, ronggui wrote:
> In that "the meaning of parent.frame depends on where it is
> evaluated", is there a nice way to figure out which frame an express
> is evaluated? for example, I would like to konw what does
> parent.frame(2) refer to.
>
>> f1 <- function(x,digits=5) lapply(x, f2)
>> f2 <- function(x) evalq(print(x+1,digits=digits),list(x=x),parent.frame(2))
>> f1(list(x1=1))
> Error in print.default(x + 1, digits = digits) :
> object "digits" not found
>
>
> On 5/27/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> The meaning of parent.frame depends on where it is evaluated. So one
>> should not expect it to do the same thing in two equivalent expressions
>> (and nor should one expect deparse to do so, for example).
>>
>> A pretty close analogy is that using a symbolic link in a file system is
>> equivalent to using the original file path, at least until you try '..' or
>> 'pwd' on the path. (In the case of 'pwd' it depends on the OS: POSIX
>> only requires '_an_ absolute pathname'.)
>>
>> On Sun, 27 May 2007, ronggui wrote:
>>
>> > The help page of eval says: The 'evalq' form is equivalent to
>> > 'eval(quote(expr), ...)'. But the following is not equivalent. Can
>> > anyone give me some explaination? Thanks very much.
>> >
>> >> f1 <- function(x,digits=5) lapply(x, f2)
>> >> f2 <- function(x)
>> eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2))
>> >> f1(list(x1=1))
>> > [1] 2
>> > $x1
>> > [1] 2
>> >
>> >>
>> >> f1 <- function(x,digits=5) lapply(x, f2)
>> >> f2 <- function(x)
>> evalq(print(x+1,digits=digits),list(x=x),parent.frame(2))
>> >> f1(list(x1=1))
>> > Error in print.default(x + 1, digits = digits) :
>> > object "digits" not found
>>
>> --
>> 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
>>
>
>
>
--
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