"Unfelicity" :-) with edit()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

"Unfelicity" :-) with edit()

François Pinard
Hi, people.  This is about R 2.3.0 under Linux.

It seems that edit() may change a function environment.  Here is
a transcript, more comments follow:

======================================================================>
> fix(f)

> f
function ()
{
}

> fix(f)
Erreur dans edit(name, file, title, editor) :
        une erreur s'est produite à la ligne 3
 utilisez une commande du genre
 x <- edit()
 pour corriger

> f <- edit()

> f
function ()
{
}
<environment: base>
======================================================================<

The initial ``fix(f)`` called an editor, which I exited right away.  For
the second ``fix(f)``, I used the editor for adding a slash between
braces, and exited.  The French comment produced by R speaks about an
error at line 3 and suggests using something like ``x <- edit()`` to
make a correction.  On the third call to the editor, I remove the slash
and exit.  Now, the environment of the function became "base".

This has unfortunate effects when editing a more substantial function,
because for example, "stats" or "utils" is not readily available anymore
after the editing.  Is it reasonable to suggest an improvement in the
mechanics of edit(), for alleviating this drawback ?

--
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: "Unfelicity" :-) with edit()

Duncan Murdoch
On 5/8/2006 9:03 PM, François Pinard wrote:

> Hi, people.  This is about R 2.3.0 under Linux.
>
> It seems that edit() may change a function environment.  Here is
> a transcript, more comments follow:
>
> ======================================================================>
>> fix(f)
>
>> f
> function ()
> {
> }
>
>> fix(f)
> Erreur dans edit(name, file, title, editor) :
>         une erreur s'est produite à la ligne 3
>  utilisez une commande du genre
>  x <- edit()
>  pour corriger
>
>> f <- edit()
>
>> f
> function ()
> {
> }
> <environment: base>
> ======================================================================<
>
> The initial ``fix(f)`` called an editor, which I exited right away.  For
> the second ``fix(f)``, I used the editor for adding a slash between
> braces, and exited.  The French comment produced by R speaks about an
> error at line 3 and suggests using something like ``x <- edit()`` to
> make a correction.  On the third call to the editor, I remove the slash
> and exit.  Now, the environment of the function became "base".
>
> This has unfortunate effects when editing a more substantial function,
> because for example, "stats" or "utils" is not readily available anymore
> after the editing.  Is it reasonable to suggest an improvement in the
> mechanics of edit(), for alleviating this drawback ?

edit() is a hack, so you should expect problems.  You're better off
keeping your source in an editor and using source() to get it.  There is
no way it could preserve the environment of a function if you go through
the steps you went through above.

However, it's a bug (introduced by me last year when converting NULL to
.BaseEnv) that it ends up with the base environment instead of the
global environment.  I'll fix it.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: "Unfelicity" :-) with edit()

François Pinard
[Duncan Murdoch]

>I'll fix it.

Thanks, Duncan.  While I quite understand that more serious work should
be done within real sources files, fixing and editing is still useful
for quick, evanescent interactive toying.

>edit() is a hack, so you should expect problems.  You're better off
>keeping your source in an editor and using source() to get it.

This is not the first time I read such a remark.  Maybe it would be
worth a note within ?edit.

>There is no way it could preserve the environment of a function [...]

That might be worth another note within ?edit.

Speaking of which, this "x <- edit()" usage (interactively suggested by
fix when it fails to re-parse the result of edition) is not covered by
?edit.  I mean that by reading ?edit, one does not get information about
what a mere "edit()" does.  It might be useful that ?edit says a few
words about this particular usage.

The remaining of this message quotes the original message:

[François Pinard]
>Hi, people.  This is about R 2.3.0 under Linux.

>It seems that edit() may change a function environment.  Here is
>a transcript, more comments follow:

>======================================================================>
>>fix(f)

>>f
>function ()
>{
>}

>>fix(f)
>Erreur dans edit(name, file, title, editor) :
>         une erreur s'est produite à la ligne 3
>  utilisez une commande du genre
>  x <- edit()
>  pour corriger

>>f <- edit()

>>f
>function ()
>{
>}
><environment: base>
>======================================================================<

>The initial ``fix(f)`` called an editor, which I exited right away.  For
>the second ``fix(f)``, I used the editor for adding a slash between
>braces, and exited.  The French comment produced by R speaks about an
>error at line 3 and suggests using something like ``x <- edit()`` to
>make a correction.  On the third call to the editor, I remove the slash
>and exit.  Now, the environment of the function became "base".

>This has unfortunate effects when editing a more substantial function,
>because for example, "stats" or "utils" is not readily available anymore
>after the editing.  Is it reasonable to suggest an improvement in the
>mechanics of edit(), for alleviating this drawback ?

--
François Pinard   http://pinard.progiciels-bpi.ca

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: "Unfelicity" :-) with edit()

Duncan Murdoch
On 5/9/2006 9:17 AM, François Pinard wrote:

> [Duncan Murdoch]
>
>>I'll fix it.
>
> Thanks, Duncan.  While I quite understand that more serious work should
> be done within real sources files, fixing and editing is still useful
> for quick, evanescent interactive toying.
>
>>edit() is a hack, so you should expect problems.  You're better off
>>keeping your source in an editor and using source() to get it.
>
> This is not the first time I read such a remark.  Maybe it would be
> worth a note within ?edit.
>
>>There is no way it could preserve the environment of a function [...]
>
> That might be worth another note within ?edit.
>
> Speaking of which, this "x <- edit()" usage (interactively suggested by
> fix when it fails to re-parse the result of edition) is not covered by
> ?edit.  I mean that by reading ?edit, one does not get information about
> what a mere "edit()" does.  It might be useful that ?edit says a few
> words about this particular usage.

Yes, it probably would be.  Just to clarify:  fix(f) *does* preserve the
environment of f, but

fix(f) # introduce a syntax error
f <- edit()

does not.

Duncan Murdoch

>
> The remaining of this message quotes the original message:
>
> [François Pinard]
>>Hi, people.  This is about R 2.3.0 under Linux.
>
>>It seems that edit() may change a function environment.  Here is
>>a transcript, more comments follow:
>
>>======================================================================>
>>>fix(f)
>
>>>f
>>function ()
>>{
>>}
>
>>>fix(f)
>>Erreur dans edit(name, file, title, editor) :
>>         une erreur s'est produite à la ligne 3
>>  utilisez une commande du genre
>>  x <- edit()
>>  pour corriger
>
>>>f <- edit()
>
>>>f
>>function ()
>>{
>>}
>><environment: base>
>>======================================================================<
>
>>The initial ``fix(f)`` called an editor, which I exited right away.  For
>>the second ``fix(f)``, I used the editor for adding a slash between
>>braces, and exited.  The French comment produced by R speaks about an
>>error at line 3 and suggests using something like ``x <- edit()`` to
>>make a correction.  On the third call to the editor, I remove the slash
>>and exit.  Now, the environment of the function became "base".
>
>>This has unfortunate effects when editing a more substantial function,
>>because for example, "stats" or "utils" is not readily available anymore
>>after the editing.  Is it reasonable to suggest an improvement in the
>>mechanics of edit(), for alleviating this drawback ?
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel