Vim Tips Wiki
(standard format)
(adjust Template:ScriptComments to remove id as no longer needed; minor tweaks)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{ScriptComments|2104|R: execute R-code from Vim on Mac OS X}}
+
{{ScriptComments|R: execute R-code from Vim on Mac OS X}}
   
 
==Comments==
 
==Comments==
Line 28: Line 28:
 
call system("osascript -e $'tell application \"R64\" to cmd \"" .command. "\"'")
 
call system("osascript -e $'tell application \"R64\" to cmd \"" .command. "\"'")
 
</pre>
 
</pre>
  +
  +
----
  +
The modified code does not work for me. [[User:Yitping|Yitping]] 08:40, May 20, 2011 (UTC)

Latest revision as of 07:37, 15 November 2011

Use this page to discuss script 2104 R: execute R-code from Vim on Mac OS X

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Comments[]

The posted version of the script replaces single-quotes with double-quotes, which is problematic when the quotes are nested.

Below I adapted the relevant portion of the script to allow for single-quotes. To interpret the alternative code (which uses a '$' in the system call), note that it seems that four backslashes are required to produce one blackslash that gets passed to Applescript.

[Note: I had trouble with escaped backslashes (`\\`). So I modified the code below. I don't really entirely understand what's going on with the backslashes between Vim and R--why do I need 16 backslashes for two to make it to R?--but this seems to work. Date: 2011-02-11]

Original code snippet:

  if a:mode == "selectedlines"
    " sending selected lines to interactive R application
    let command = join(getline(a:firstline,a:lastline),"\\n")
    let command = substitute(command,"\"","\\\\\"","g")
    let command = substitute(command,"\'","\\\\\"","g")
    call system("osascript -e 'tell application \"R\" to cmd \"" .command. "\"'")

Modified code snippet:

  if a:mode == "selectedlines"
    " sending selected lines to interactive R application
    let command = join(getline(a:firstline,a:lastline),"\n")
    let command = substitute(command,"\\","\\\\\\\\\\\\\\\\","g")
    let command = substitute(command,"'","\\\\'","g")
    let command = substitute(command,"\"","\\\\\\\\\"","g")
    call system("osascript -e $'tell application \"R64\" to cmd \"" .command. "\"'")

The modified code does not work for me. Yitping 08:40, May 20, 2011 (UTC)