[ESS] Interact with ESS from R

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Jun 1 17:10:52 CEST 2015


>>>>> Sparapani, Rodney <rsparapa using mcw.edu>
>>>>>     on Mon, 1 Jun 2015 13:57:09 +0000 writes:

    >> Dear All,
    >> 
    >> I am trying to make crayon
    >> (http://www.r-pkg.org/pkg/crayon) work with Emacs more
    >> smoothly. crayon can add ANSI color to strings printed to
    >> the terminal.
    >> 
    >> As I understand from
    >> http://www.emacswiki.org/emacs/AnsiColor recent versions
    >> of Emacs support this out of the box, as long as
    >> (add-hook 'shell-mode-hook
    >> 'ansi-color-for-comint-mode-on) (add-to-list
    >> 'comint-output-filter-functions
    >> 'ansi-color-process-output) was done.
    >> 
    >> I can check the version of Emacs from the INSIDE_EMACS
    >> environment variable, so I can easily tell if it is
    >> recent enough to have ansi-color.el. So far so good.
    >> 
    >> Is there a way to check if 'ansi-color-for-comint-mode-on
    >> was run and if 'comint-output-filter-functions contains
    >> 'ansi-color-process-output?
 
    > It is trivial is it not?  If
    > 'ansi-color-for-comint-mode-on was run, then
    > ansi-color-for-comint-mode should be t, right?  (Just make
    > sure it is set to nil prior) To detect
    > 'ansi-color-process-output, just try something like (memq
    > 'ansi-color-process-output comint-output-filter-functions)

    >> In general, can I call Emacs lisp functions from the
    >> embedded R process?

    > Now, you got me there ;o)

Yes... and of course that was I think the real gist of Gabor's
question.

I don't think we can do this ... and honestly I would not know
how this could be done in general.  Emacs does run the R
process, so in this sense, emacs/ESS is the master and R is the
slave.

You *can* easly find out from that you are running inside ESS,

    > any("ESSR" == search())
    [1] TRUE

or

    > "ESSR" %in% search()
    [1] TRUE

but not much more, currently.
you can see the R helpers that ESS uses and calls,

  > ls("ESSR", all=TRUE)
   [1] ".ess_all_functions"            ".ess_arg_help"                
   [3] ".ess_dbg_getTracedAndDebugged" ".ess_dbg_UndebugALL"          
   [5] ".ess_dbg_UntraceOrUndebug"     ".ess_find_funcs"              
   [7] ".ess_funargs"                  ".ess_get_completions"         
   [9] ".ess_knit"                     ".ess_log_eval"                
  [11] ".ess_package_attached"         ".ess_sweave"                  
  [13] ".ess_vignettes"                ".ess_watch_assign_expressions"
  [15] ".ess_watch_eval"               ".ess_watch_expressions"       
  [17] ".ess_weave"                    ".ess.ESSRversion"             
  [19] ".ess.eval"                     ".ess.findFUN"                 
  [21] ".ess.getHelpAliases"           ".ess.help"                    
  [23] ".ess.helpFUN"                  ".ess.R.has.utils"             
  [25] ".ess.Rversion"                 ".ess.source"                  
  [27] ".ess.sourceFUN"                ".ess.utils.name"              
  [29] ".ESSBP."                       ".essDev_assign"               
  [31] ".essDev_differs"               ".essDev_evalSource"           
  [33] ".essDev_identicalClass"        ".essDev_insertMethods"        
  [35] ".essDev_source"                ".essDev.eval"                 
  [37] "htsummary"                    

and now of course you can start hacking these (replacing them by
hacked versions!) from the R side.  But currently this cannot be
used to bring ESS to eval emacs lisp expressions.

We could enable this though, at least by something like
a hook,

R code equivalent would be something like

  if(is.character(as.environment("ESSR")$emacs.eval))
      ## in emacs, take the    as.environment("ESSR")$emacs.eval
      ## and evaluate it as emacs lisp code

and ESS would do this "every time" after sending R code to
the process, or something similar ?
or it would remove the character code, after eval()ing it ?

Opinions?


    >> I am sorry if this is documented somewhere, I tried to
    >> find it in the docs, without luck.
    >> 
    >> Thanks, Best, Gabor
    >> 

    > ______________________________________________
    > ESS-help using r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/ess-help




More information about the ESS-help mailing list