Send code from Sublime Text to rgui on Windows. Adapted from randy3k's SendCode Sublime Package.
Features
- Work with multiple rgui's. Code will be sent to the last active rgui.
- Send code as text directly to the rgui console or source a temp file containing selected code (sourcing a temp file is helpful in that the execution breaks off at the first error in the selected code).
- Send code from unsaved file (helpful for quick debugs).
- Work with clipboard within rgui (helpful for quick data transfers, e.g. to Excel)
Copy this repository into your Sublime Text Packages directory (under Packages\RGUI)
- Packages directory location: In Sublime Text go to Preferences > Browse Packages... to open the Packages folder.
Default keybindings:
-
F4
Sets the working directory to the path of the current file.
-
F5
Sources the whole (unsaved) script as a temp file. Equivalent to select all and f6 (see below).
-
F6
Sources the selected text as a temp file.
-
F7
If text is selected, sends the text to the rgui (as copy and paste would). If no text is selected, then it sends the current line (or block). Finally, it moves the cursor to the next line.
-
F12
Removes all objects from .
-
Ctrl+Insert
Copies the contents of selected variable or the selected code output to the clipboard.
-
RGui window not found
Make sure RGui is running before sending code. If you get the message "Rgui window not found", check that the r_console_title setting matches your RGui window title exactly. You can see the title in the RGui title bar — common values are "R Console (64-bit)" and "R Console (32-bit)".
-
Code not pasting correctly
The plugin works by copying code to the clipboard and pasting it into RGui. If code arrives incomplete or garbled, try increasing the r_paste_delay setting (e.g. to 0.05 or 0.1).
-
Clipboard is overwritten
The plugin temporarily uses the system clipboard to transfer code. Your previous clipboard content is restored afterward, but if the paste fails mid-way (e.g. RGui is unresponsive), the clipboard may not be restored.
-
Multi-line code doesn't execute fully
For very long or complex code selections, use the 'F6' method (see the default keybindings). This writes the code to a temp file and calls source() in RGui, which is more reliable for multi-line code.
-
Windows only
This plugin uses the Windows API (ctypes.windll) to communicate with RGui and does not work on macOS or Linux.