Menu

#252 S+/R mode - Process Current File (Cmd^T) fails

9.2.3
closed
nobody
S+/R mode (1)
Bug
critical
2021-06-01
2021-05-13
No

The essential menu command "S+/R -> Process Current File" of the S+/R mode fails. It does no longer source, i.e. it does not process the current file. I am sorry to lack the time right now to figure out why that is. Perhaps it is the R GUI app which has changed, but then Alpha might need to adjust what Apple Event it sends to R. In any case, INMHO the mode is crippled by this problem. Does anyone perhaps know a solution to this problem? I would greatly appreciate getting any hints on how to circumvent this if bigger modifications would be required to the mode as this is rather at the moment urgent for me. Thanks.

Alpha 9.2.2 (10145) -- R 3.6.1 GUI 1.70 El Capitan build -- OS X 10.14.6 (Mojave)

Discussion

  • Bernard Desgraupes

    Hi Andreas,
    do you get an error message ?
    If not, could you try to execute the command from the Tcl Shell like this

    S::processCurrentFile /path/to/the/script.R
    

    where you replace /path/to/the/script.R by the full path of your R script. See if you get an error message.

     
  • Fischlin Andreas

    I updated R to R 4.0.5 GUI 1.74 Catalina build (7950). This works better as the script steps are at least not only shown but also executed acceptably fast now. However, the R script file is still not sourced as was previously the case.

     
    • Eberhard W Lisse

      I don't use R GUI, only the R command line (and R Studio).

      On start and when doing the TCL Shell I get

      Error: Can't find app with id 'org.R-project.R'
      

      I think I have used every possible way of connecting /usr/local/bin/R
      (which is a symlink) to Alpha. in the Helper Apps it points to the realpath
      of R after connecting the symlink.

      Alpha 9.2.2
      R version 4.0.4/4.0.5 (homebrew)
      Big Sur 11.3.1

      I really would like to be able to use Alpha with R (commandline)

      greetings, el

       

      Last edit: Bernard Desgraupes 2021-05-13
  • Fischlin Andreas

    I tried to execute from the Tcl Shell and get the same. No error message, instead of sourcing the entire script is shown in the R console. I attach a screenshot from R's console so you can see the difference. This is a new behavior. In the attached screenshot you see first the end of the processed R script as sent from Alpha, then I have manually written a comment explaining that I would now source the very same file (at the bottom). With the updated R, the speed is again acceptable and I can at least use Cmd^T for graphs. Before, i.e. with the previous R version, the new behavior was incredibly slow. Yet, I would like R to only source the file, so that one can focus on the output from the script, not having to see the script being repeated and mixed with the results in the messy way it does that right now. IMHO it would be good if the S+/R mode returns to simply asking R to source the current file. Perhaps for debugging purposes of R-scripts an option to "process the current file" in this manner may be useful. But not for real work with R.

     
  • Fischlin Andreas

    Bonjour Bernard,
    Thanks for any hints on this issue (which is perhaps not a bug ;-) ).
    Andreas

     
  • Bernard Desgraupes

    Hmm, at this point I get confused. You have a command Source A File if you only want to source the file without seeing all the instructions in the R console.
    Concerning the slowness, isn't it because your script demands a lot of work on the R side ?

     
  • Fischlin Andreas

    Ok. Let me explain: I guess you mean the menu command in Alpha's S+/R mode menu 'Source A Script...'. This command is not of much use, as it is cumbersome and you have to go through the file selection dialog and reselecting the file you have currently open in Alpha to accomplish the sourcing. That is about the same as switching to R and there to issue the correspondng menu command "File -> Source File...". True, these commands do what the S+/R mode has been doing previously when issuing Cmd^T, i.e. selecting the menu command 'S+/R -> Process Current File'.

    I believe it is much, much more preferable to return to the previous behavior and source the current file when issuing Cmd^T. The current behavior, if to be retained at all, would need to go to another, new menu command in the S+/R mode menu and could perhaps be issued with shortcut Cmd^Opt^T. But the crucial Cmd^T needs to source again the file.

    Note, similarly, the mode menu commands "S+/R -> Process Selection" need also to return to the previous behavior of only sourcing that selection. Perhaps, here you could argue that the current behavior would be more acceptable, as you might use that command often when debugging R scripts. However, I favor for sure the old behavior as many of my R scripts are complex and produce also complex calculation results, which become unreadable whith the current behavior.

    Another option than adding new menu comamnds retaining the current behavior might be to switch to some debugging mode via a preference and adding only a toggling menu command. In the debugging mode you would have the current behavior, in the normal default mode, the old behavior of merely sourcing the script (or script selection).

    The issue with the speed with the older R version 3.6.1 is the fact that the script is not sourced, but somhow slowly, line by line accepted and interpreted and processed in such a slow manner, that the Cmd^T is basically unusable. With the exactly same software sourcing the very same script, everything R does is back to normal speed. Therefore, for the older R versions, the new approach seems to me to be alone for speed reasons a no go. R script code needs there to be sourced as always.

     
  • Bernard Desgraupes

    I'm not sure what you call "previous behavior" since Alpha's R mode has been working like this for several years now.
    Anyway, what you want to achieve is quite simple to implement. Here is an implementation that you can copy in your file SPrefs.tcl :

    proc S::sourceCurrentScript {} {
        global SmodeVars mode
    
        set f [win::Current]
        if {$f eq ""} {
            return
        } 
        if {$mode ne "S"} {
            alertnote "Current file is not in S+/R mode."
        } 
    
        if {[winDirty] && [askyesno \
          "Do you want to save the file before sending it to $SmodeVars(rApp)?"]} {
            save
        } 
    
        if {$SmodeVars(stayInAlpha)} {
            app::launchBack [S::bundleID]
        } else {
            app::launchFore [S::bundleID]
        }
        xserv::invoke sourceRFile -file $f
    
        return
    }
    
    binding create -tag S {coz 'T'} S::sourceCurrentScript
    

    The last line defines a ctrl-opt-cmd T binding to this new proc called S::sourceCurrentScript.
    After you copy this in your file SPrefs.tcl, then quit Alpha and relaunch it: now you can just press ctrl-opt-cmd T to get your current file sent to R.app as a source command.
    Whether this new implementation should become the default for the Process Current File command in Alpha's R menu may be debated. I have no objection: the current behaviour could be handled by the Process Selection command when the selection is ... empty (!).

     
    • Fischlin Andreas

      Dear Bernard,

      Perhaps one more thing on this: As I said initially, this may also be the result from changes in R and it could well be that Alpha’s S+/R mode is not the reason for the change in behavior.

      Andreas

      ETH Zurich
      Prof. em. Dr. Andreas Fischlin
      IPCC Vice-Chair WGII
      Systems Ecology - Institute of Biogeochemistry and Pollutant Dynamics
      CHN E 24
      Universitaetstrasse 16
      8092 Zurich
      SWITZERLAND

       

      Last edit: Bernard Desgraupes 2021-05-14
  • Fischlin Andreas

    Thanks a lot Bernard (merci beaucoup). It works like a charm, I just use Cmd^T (all other T related shortcuts are already in use by many other processes). Works nicely as the new Cmd^T ;-)

    BTW, yes, as far back as I can remember (many, many years of R use with Alpha) Cmd^T has sourced the R script. But I have to admit, I do not remember when that changed, as I have not used R since several months now.

     
  • Bernard Desgraupes

    So I have implemented this new behaviour in Alpha 9.2.3 (soon to be released).
    Marking this ticket as fixed.

     
  • Bernard Desgraupes

    • status: open --> fixed
     
  • Bernard Desgraupes

    • status: fixed --> closed
    • Version: 9.2.2 --> 9.2.3
     

Log in to post a comment.