From skostysh at princeton.edu  Tue Sep  9 09:15:47 2014
From: skostysh at princeton.edu (Scott Kostyshak)
Date: Tue, 9 Sep 2014 03:15:47 -0400
Subject: [Rd] [patch] Add support for editor function in edit.default
In-Reply-To: <CADfFDC7p8QpFbyQvFMujxOT-E_zFGLZT3ecRgzBtuYLb1Ya8tw@mail.gmail.com>
References: <CAE3=dmfOvQQPcWu8=5+_Nd-EXE8HAnywrT9g67pYfxBx0exWxQ@mail.gmail.com>
	<CAE3=dmcNk_oSHdbKGjTAsCL0Kk6MDt+F-zeyn+KwG-myXUk9EQ@mail.gmail.com>
	<CADfFDC7p8QpFbyQvFMujxOT-E_zFGLZT3ecRgzBtuYLb1Ya8tw@mail.gmail.com>
Message-ID: <CAE3=dmcAoNVCmDYSkVtOiBe_DQJPK5v0yiT3dMrCaSddujNnzA@mail.gmail.com>

On Tue, Sep 9, 2014 at 2:24 AM, Deepayan Sarkar
<deepayan.sarkar at gmail.com> wrote:
> On Sun, Aug 24, 2014 at 9:14 AM, Scott Kostyshak <skostysh at princeton.edu> wrote:
>> On Tue, May 20, 2014 at 5:55 AM, Scott Kostyshak <skostysh at princeton.edu> wrote:
>>> Regarding the following extract of ?options:
>>>      ?editor?: a non-empty string, or a function that is called with a
>>>           file path as argument.
>>>
>>> edit.default currently calls the function with three arguments: name,
>>> file, and title. For example, running the following
>>
>> To be clear with what I view as problematic, note in the above that
>> the documentation says the function is called with a file path as an
>> argument, suggesting one argument; but in practice it is called with
>> three arguments.
>>
>>> vimCmd <- 'vim -c "set ft=r"'
>>> vimEdit <- function(file_) system(paste(vimCmd, file_))
>>> options(editor = vimEdit)
>>> myls <- edit(ls)
>>>
>>> gives "Error in editor(name, file, title) : unused arguments (file, title)".
>>>
>>> The attached patch changes edit.default to call the editor function
>>> with just the file path. There is at least one inconsistent behavior
>>> that this patch causes in its current form. It does not obey the
>>> following (from ?edit):
>>>      Calling ?edit()?, with no arguments, will result in the temporary
>>> file being reopened for further editing.
>>>
>>> I see two ways to address this: (1) add a getEdFile() function to
>>> utils/edit.R that calls a function getEd() defined in edit.c that
>>> returns DefaultFileName; or (2) this patch could be rewritten in C in
>>> a new function in edit.c.
>>>
>>> Is there any interest in this patch?
>>> If not, would there be interest in an update of the docs, either
>>> ?options (stating the possibility that if 'editor' is a function, it
>>> might be called with 'name', 'file', and 'title' arguments) or ?edit
>>>  ?
>>
>> Any interest in this patch? If not, would a patch for the
>> documentation be considered?
>
> Given that edit() itself is called with the three arguments, it seems
> more general to pass them to the editor function, and I don't see the
> need for a special case. You can always write your function as
>
> vimEdit <- function(file_, ...) system(paste(vimCmd, file_))

Indeed, makes sense.

> I will clarify the documentation.

Great. Thanks a lot for taking the time to understand the issue.

Best,

Scott


--
Scott Kostyshak
Economics PhD Candidate
Princeton University



[Rd] [patch] Add support for editor function in edit.default
Scott Kostyshak