To Dirk and Ivan,

Thank you for your suggestions. Let's give more details. The idea is to insert the code in a function and then in a (private) package. We have to rely on the default editors provided by the OS to R and cannot invent a new editor, as R CMD check could fail on exotic platforms. We cannot assume that Geany, even nano, is available everywhere. Something like:

switch(Sys.info()[["sysname"]],
  "Windows" = switch(type,
    "pager"  = file.show(filename, header = filename, title = "Pager"),
    "editor" = file.edit(filename, title = filename, fileEncoding = ""),
    shell.exec(filename)
    ),
  "Darwin"  =  switch(type,
    "pager"  = file.show(filename, header = filename, title = "Pager"),
    # "editor" = system2(getOption("editor"), filename, wait = FALSE),
    system2("open", filename, wait = FALSE)
    ),
  switch(type,
    "pager" = file.show(filename, header = filename, title = "Pager"),
    # "editor" = system2(getOption("editor"), filename, wait = FALSE),
    system2("xdg-open", filename, wait = FALSE)
    )
)

The instruction for the pager

  file.show(filename, header = filename, title = "Pager")

launchs the pager on Windows, Debian and macOS and it works fine on these 3 platforms. On Debian, it is within the R console and it terminates properly and gives the hand back to R.

The instruction for the text editor

 system2(getOption("editor"), fileREP, wait = FALSE)

works fine on Windows (it opens Notepad.exe, or Notepad++.exe in my Rprofile.site) but not on Unix. I assumed there was something similar on Unix (You have understood that I am not a Unix specialist). R includes a few library statically compiled. Could R incorporate a decent text editor on Unix Oses?


Dirk, I will watch your videos. Thank you for these links. I discover them.

Patrice



Le 17/12/2021 à 20:20, Dirk Eddelbuettel a écrit :
Patrice,
Also: if you are on a terminal, have you discovered tmux / byobu yet to multiplex? It is fairly magic as you can just open as many 'sessions with the outer sessions', the sessions persist and many more advantages. I talked a little about this (with short videos) last year
   https://dirk.eddelbuettel.com/blog/code/t4/
in episodes 4, 5 and 6.
Dirk


Le 17/12/2021 à 19:46, Ivan Krylov a écrit :
   system2(getOption("editor"), fileREP, wait = FALSE)
Starting a new terminal is somewhat hard, but the shortest path to
getting this particular command working would be options(editor =
'gvim'). It's almost like Vim in a terminal, plus a few features useful
in a windowed interface.
Note that gvim backgrounds itself by default, so this would break
edit() and file.edit(): since the GVim process started by R terminates
almost immediately after spawning a child to do the rest of the work, R
decides that the editing session is done. Unfortunately, it's hard to
make R's edit() pass the -f flag to gvim to prevent it from doing that,
but a trivial shell script wrapper could be used for that purpose:
> #!/bin/sh
> exec gvim -f "$@"

_______________________________________________
R-SIG-Debian mailing list
R-SIG-Debian@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-debian

Reply via email to