Dear list readers,
Can someone of you explain this behavior. Here's a toy example:
Start by constructing a function tmp
>fix(tmp)
In the default editor enter this one-liner:
hist(rnorm(10))
close the editor and run environment on the function.
> environment(tmp)
<environment: R_GlobalEnv>
Open the editor and remove the last parenthesis, this will make the
editor choke.
> fix(tmp)
Error in edit(name, file, title, editor) :
an error occurred on line 4
use a command like
x <- edit()
to recover
Put the paranthesis back:
> edit()->tmp
> environment(tmp)
<environment: base>
> tmp()
Error in tmp() : could not find function "hist"
And as you can see, the function doesn't work anymore...
Yes, I know I can manually change the environment back to .GlobalEnv,
but is this the way it supposed to work?
This example is done in
> R.Version()$version.string
[1] "Version 2.3.0 Patched (2006-04-25 r37924)"
on WindowsXP
Cheers, Hans
--
*********************************
Hans Gardfjell
Ecology and Environmental Science
Ume? University
90187 Ume?, Sweden
email: hans.gardfjell at emg.umu.se
phone: +46 907865267
mobile: +46 705984464
Hans Gardfjell wrote:> Dear list readers, > > Can someone of you explain this behavior. Here's a toy example: > > Start by constructing a function tmp > > >fix(tmp) > > In the default editor enter this one-liner: > hist(rnorm(10)) > > close the editor and run environment on the function. > > > environment(tmp) > <environment: R_GlobalEnv> > > Open the editor and remove the last parenthesis, this will make the > editor choke. > > > fix(tmp) > Error in edit(name, file, title, editor) : > an error occurred on line 4 > use a command like > x <- edit() > to recover > > Put the paranthesis back: > > > edit()->tmp > > > environment(tmp) > <environment: base> > > tmp() > Error in tmp() : could not find function "hist" > > And as you can see, the function doesn't work anymore... > Yes, I know I can manually change the environment back to .GlobalEnv, > but is this the way it supposed to work?No, but it has already been fixed. Please try the beta version of R-2.3.1. Uwe Ligges> This example is done in > > > R.Version()$version.string > [1] "Version 2.3.0 Patched (2006-04-25 r37924)" > > on WindowsXP > > Cheers, Hans >
Your R-patched is nearly a month old. For 2.3.1 beta:
o edit() would default the environment of a function to .BaseEnv,
instead of to .GlobalEnv.
so this is already changed in the current test versions of the next
release of R.
On Tue, 23 May 2006, Hans Gardfjell wrote:
> Dear list readers,
>
> Can someone of you explain this behavior. Here's a toy example:
>
> Start by constructing a function tmp
>
> >fix(tmp)
>
> In the default editor enter this one-liner:
> hist(rnorm(10))
>
> close the editor and run environment on the function.
>
> > environment(tmp)
> <environment: R_GlobalEnv>
>
> Open the editor and remove the last parenthesis, this will make the
> editor choke.
>
> > fix(tmp)
> Error in edit(name, file, title, editor) :
> an error occurred on line 4
> use a command like
> x <- edit()
> to recover
>
> Put the paranthesis back:
>
> > edit()->tmp
>
> > environment(tmp)
> <environment: base>
> > tmp()
> Error in tmp() : could not find function "hist"
>
> And as you can see, the function doesn't work anymore...
> Yes, I know I can manually change the environment back to .GlobalEnv,
> but is this the way it supposed to work?
>
> This example is done in
>
> > R.Version()$version.string
> [1] "Version 2.3.0 Patched (2006-04-25 r37924)"
>
> on WindowsXP
>
> Cheers, Hans
>
>
--
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