Randy Lai
2018-Aug-28 19:07 UTC
[Rd] "utils::file.edit" does not understand "editor" with additional arguments
I am using Sublime Text as my editor. If I run `subl -n .Rprofile` in bash, a file would be opened in a new window. Back in R, if I run this> file.edit(".Rprofile", editor="'subl -n'")sh: 'subl -n': command not found Warning message: error in running command However, the interesting bit happens when I run edit(1:10, editor="'subl -n?") It does open Sublime Text. It seems that `file.edit` and `edit` are behaving differently when ?editor? has additional arguments. Randy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: Message signed with OpenPGP URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20180828/28f66613/attachment.sig>
Prof Brian Ripley
2018-Aug-30 06:14 UTC
[Rd] "utils::file.edit" does not understand "editor" with additional arguments
We do not have the 'at a minimum' information requested by the posting guide, and I cannot reproduce anything like this on a Unix-alike. Both file.edit and edit.default call the same underlying C code, and that single-quotes the 'editor' argument to allow for spaces in its path/name so I would not expect this to work. Two workarounds: 1) Set an alias in your shell (e.g. in .bashrc) for 'subl -n'. This is something widely needed on macOS where many editors are invoked by 'open -a', and I also use it for 'emacsclient -n'. 2) Make use of the ability to specify editor as an R function, invoking the external program by system2() etc. On 28/08/2018 20:07, Randy Lai wrote:> I am using Sublime Text as my editor. If I run `subl -n .Rprofile` in bash, a file would be opened in a new window. > > Back in R, if I run this > >> file.edit(".Rprofile", editor="'subl -n'") > sh: 'subl -n': command not found > Warning message: > error in running command > > However, the interesting bit happens when I run > > edit(1:10, editor="'subl -n?") > > It does open Sublime Text. It seems that `file.edit` and `edit` are behaving differently when ?editor? has additional arguments. > > Randy-- Brian D. Ripley, ripley at stats.ox.ac.uk Emeritus Professor of Applied Statistics, University of Oxford