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-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_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