Send R code from Atom to be executed in R.app, Terminal, iTerm, or a web browser running RStudio Server on Mac OS X. The current selection is sent or in the case of no selection the current line is sent.
apm install r-exec
or
Search for r-exec
within package search in the Settings View.
While cmd-enter
is bound to sending code in the package, it is also annoyingly bound to entering a new line by default in atom.
In order to make it work, you must add the following binding in ~/.atom/keymap.cson
:
'atom-workspace atom-text-editor:not([mini])':
'cmd-enter': 'r-exec:send-command'
All configuration can be done in the settings panel. Alternatively, you can edit your configuration file as noted below.
In your global configuration file (~/.atom/init.coffee
), you may set the following variables:
r-exec.whichApp
which R application to use. Valid applications are:R.app
: the default (the R GUI)iTerm
orTerminal
: Assumes the currently active terminal has R runningSafari
orGoogle Chrome
: assumes the currently active tab has an active RStudio session running, with the console active
r-exec.advancePosition
- if
true
, go to the next line/paragraph after running the current line/paragraph - if
false
, leave the cursor where it currently is
- if
r-exec.focusWindow
- if
true
, focus the window before sending code - if
false
, send the code in the background and stay focused on Atom. This is not possible when sending code to a browser
- if
r-exec.notifications
- if
true
, notifications viaNotificationManager
when a paragraph or function is not identified
- if
The default configuration looks like this:
atom.config.set('r-exec.whichApp', 'R.app')
atom.config.set('r-exec.advancePosition', false)
atom.config.set('r-exec.focusWindow', true)
atom.config.set('r-exec.notifications', true)
The iTerm2 Applescript API recently changed as of version 3.0.0.
Older versions of iTerm2 (< 3.0.0) are supported using mode iTerm
.
Newer versions of iTerm2 (>= 3.0.0) are supported using mode iTerm2
.
cmd-enter
: send code to configured application (r-exec:whichApp
).shift-cmd-e
: change to current working directory of current file.shift-cmd-k
: send code between a knitr block (currently only RMarkdown supported).shift-cmd-u
: send function under current cursor. Currently, only functions that begin of the first column in and on the first column of a line are sent. An example:
myFunction <- function(x) {
# my code goes here
}
shift-cmd-m
: send paragraph under current cursor. A paragraph is a region enclosed by whitespace.
This is very much in an alpha state and is a quick hobby project. It is currently Mac-only because these things are easy to do with AppleScript. Any help on the Windows or Linux side would be great.
In the RStudio Server case, the solution is pretty clunky - the code is sent to the clipboard and then a paste command is sent to Safari. But it works.
- Make the choice of which R.app to send the code to configurable, based on a project-level configuration variable (sometimes multiple copies of R.app are made so that multiple R GUIs can be running simultaneously for different projects).
- In RStudio Server case, make sure active window really is RStudio Server before pasting, maybe by checking the title.
- Error reporting.
- Support for Windows and Linux.