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

2014-05-20 Thread Scott Kostyshak
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

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
 ?

Scott


> sessionInfo()
R Under development (unstable) (2014-05-20 r65677)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


--
Scott Kostyshak
Economics PhD Candidate
Princeton University
Index: src/library/utils/R/edit.R
===
--- src/library/utils/R/edit.R	(revision 65677)
+++ src/library/utils/R/edit.R	(working copy)
@@ -53,7 +53,13 @@
   editor = getOption("editor"), ...)
 {
 if (is.null(title)) title <- deparse(substitute(name))
-if (is.function(editor)) invisible(editor(name, file, title))
+if (is.function(editor)) {
+if (file == "") file <- tempfile()
+objDep <- if (is.null(name)) "" else deparse(name)
+writeLines(objDep, con = file)
+editor(file)
+eval(parse(file))
+}
 else .External2(C_edit, name, file, title, editor)
 }
 
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Question about fifo behavior on Linux between versions 3.0.3 and 3.1.0

2014-05-20 Thread James Smith
Version 3.1.0 of R has imposed a very small data limit on writing to fifos on 
Linux. Consider the following R code (Assumes that "ff" is a fifo in the R 
process's current directory):

con <- fifo("ff", "a+b")
writeBin(raw(12501), con)

In R 3.0.3, this returns without error and the data is available on the fifo. 
In R 3.1.0, however, this returns the following error:

Error in writeBin(raw(12501), con) : too large a block specified

In investigating R's source, the difference seems to be in 
src/main/connections.c, in the function fifo_write() (around line 932). In R 
3.0.3, fifo_write() has these lines:

if ((double) size * (double) nitems > SSIZE_MAX)
error(_("too large a block specified"));

R 3.1.0 has these lines changed to this:

if ((size * sizeof(wchar_t) * nitems) > 5) {
  error(_("too large a block specified"));
}

The change effectively places a limit of 12500 bytes on writes (since 
sizeof(wchar_t) == 4). Does anyone know why this change was made? I understand 
that fifos on Windows were implemented for R 3.1.0, but the code for fifos on 
Windows is in a separate part of connections.c that doesn't get compiled on 
Linux (i.e., the code given is Unix only). I also couldn't find any references 
to fifo behavior changes under Linux in any of R's documentation.

My platform is Fedora 20 (64-bit) and I have built and installed R from source.

Thank you for your time and consideration.

James O Smith
Harmonia Holdings Group, LLC

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Question about fifo behavior on Linux between versions 3.0.3 and 3.1.0

2014-05-20 Thread Prof Brian Ripley
It _was_ part of the fifo for Windows patch.  As if does not seem to be 
needed for Windows, it has been reverted.



On 20/05/2014 16:02, James Smith wrote:

Version 3.1.0 of R has imposed a very small data limit on writing to fifos on Linux. 
Consider the following R code (Assumes that "ff" is a fifo in the R process's 
current directory):

con <- fifo("ff", "a+b")
writeBin(raw(12501), con)

In R 3.0.3, this returns without error and the data is available on the fifo. 
In R 3.1.0, however, this returns the following error:

Error in writeBin(raw(12501), con) : too large a block specified

In investigating R's source, the difference seems to be in 
src/main/connections.c, in the function fifo_write() (around line 932). In R 
3.0.3, fifo_write() has these lines:

 if ((double) size * (double) nitems > SSIZE_MAX)
error(_("too large a block specified"));

R 3.1.0 has these lines changed to this:

 if ((size * sizeof(wchar_t) * nitems) > 5) {
   error(_("too large a block specified"));
 }

The change effectively places a limit of 12500 bytes on writes (since 
sizeof(wchar_t) == 4). Does anyone know why this change was made? I understand 
that fifos on Windows were implemented for R 3.1.0, but the code for fifos on 
Windows is in a separate part of connections.c that doesn't get compiled on 
Linux (i.e., the code given is Unix only). I also couldn't find any references 
to fifo behavior changes under Linux in any of R's documentation.

My platform is Fedora 20 (64-bit) and I have built and installed R from source.

Thank you for your time and consideration.

James O Smith
Harmonia Holdings Group, LLC

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel




--
Brian D. Ripley,  rip...@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, UKFax:  +44 1865 272595

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel