Mac - Sublime Text and R - r

I am trying to write my first line in R using sublime text.
First I installed the SublimeREPL and enhance R packages. I edited the user settings to:
{
"default_extend_env": {"PATH": "{PATH};~/Applications/R.app"},
"show_transferred_text": true
}
Now I can launch REPL r without any trouble.
What I'd like to do know is to write some R code in one of my tabs and execute it automatically in the REPL r window.
What is happening now is when I use the cmd+enter shortcut to execute my selected code, it is executed but in the R.app console not in my REPL [r] window in sublime.
How can I fix this?
Thanks

EDIT: Currently the functionality moved from R-Box to SendREPL (see
README here: https://github.com/randy3k/SendREPL).
After installing SendREPL, you need to bring up the command palette and search for SendREPL: Choose REPL Program
You need to change Enhanced-R.sublime-settings (User) from
"osx":
{
"App": "R"
},
to
"osx":
{
"App": "SublimeREPL"
},
Which also can be done by bringing up command panel (ctrl+shift+p on linux/windows or cmd+shift+p on mac) and search for R Application Switch and then select SublimeREPL
Note that Enhanced-R has been deprecated. Use R-Box

Related

How to run Python, R, Octave or Julia using BowPad?

I try using a very light-weighted editor BowPad to edit and run codes.
Take running R as an example, which has been added to Windows PATH Environment Variable D:\R\R-3.6.2\bin\x64
I try to take some following steps:
I built a test.r writing some testing line codes as 1+2; plot(1:10)
Menu --> Run --> Configure custom commands
Command Name: run R
Command Line: D:\R\R-3.6.2\bin\R.exe $(SEL_TEXT)
$(LINE) The line where the cursor is
$(POS) the position where the cursor is
$(TAB_PATH) the path to the file of the active tab
$(TAB_NAME) the file name without extension of the current tab
$(TAB_EXT) the file extension of the current tab
$(TAB_DIR) the directory of the file of the active tab
$(SEL_TEXT) the selected text or the word at the cursor position
$(SEL_TEXT_ESCAPED) like $(SEL_TEXT) but escaped, useful for urls
When I press to choose run R to run the code, something wrong happens!
It will open a Rterm(64-bit) window each time when I run R!
it shows RGUMENT '1+2' __ignored__ or ARGUMENT 'plot(1:10)' __ignored__
Did I missing something ? BTW, can we set some shortcuts keys for running Python, R, Octave or Julia?
Also, when I reach the homepage of BowPad for more information, little usage of this software can be found!
R.exe refers to Rterm. You can use Rgui.exe instead but that won't automatically process arguments. I think what you likely want is to send the selected text to a running R session rather than starting up a new R session each time.
To do that
download this file and optionally place it on your path https://raw.githubusercontent.com/ggrothendieck/batchfiles/master/clip2r.js
in the Bowpad Run | Configure window configure a Run R command as the following (or if clip2r.js is not on your path use the entire pathname). It should be just like this with no arguments.
clip2r.js
From the Windows cmd line if Rgui is running we see that tasklist | findstr Rgui finds Rgui as the R gui process and you can create additional js scripts by editing clip2r.js replacing Rgui in the js script with whatever is the appropriate word to locate python, julia, octave or other R front end assuming again that they are running.
Now to invoke it from within Bowpad:
ensure that your Rgui session is already running and
from within Bowpad select the code you want to run and copy it to the clipboard and then invoke Run R. For example, to run everything use ctrl A ctrl C ctrl R 0 assuming that Run R is in position 0 in the configure menu. Alternately use the mouse with the Ribbon.
Regarding the comment about difficulty finding help, it looks like Bowpad is based on Scintilla so the documentation for it and the related SciTE editor likely apply to Bowpad too. You can also check the Bowpad source code on github.

Source on save R file in Eclipse StatET

I'm starting learning R with coursera.org. I've chosen Eclipse Java Neon with StatET plugin as editor and here is my question. Is any more efficient way to loading file to R console instead writing source("file.R") after every change in this file? I mean about something like "Source on save" in RStudio.
Running R documents
What I use the most is simply selecting in the window the part I want to run and run
Ctrl+R Ctrl+R
if I want to run the whole file
CtrlA+ Ctrl+R Ctrl+R
if I want to run the R script by submitting directly
Crtl R + Ctrl D
or
right click in the document, run as
If I want to save the file first Ctrl+S
you can also use the buttons in the toolbar at the top, they will let you learn the shortcuts.
If you prefer different shortcuts.
Window>Preference>General>Keys and edit the shortcuts you want to have.

Atom/Sublime like Multiple selections in Jupyter

How can I select matching keywords in a Jupyter notebook via a keyboard shortcut? For example, in the Atom/Sublime editor I can hit cmd + D on a mac (or Ctrl + d on Windows) while the cursor is over 'var' and each time I do that the next 'var' will be highlighted. I can then type the new variable name and 'var' is replaced with whatever I typed.
var = "hello"
print(var)
print(var)
Is there an equivalent in a Jupyter notebook?
Add custom.js to
C:\Users\username\.jupyter\custom # for Windows and
~/.jupyter/custom/ # for Mac
with content
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
cell.Cell.options_default.cm_config.keyMap = 'sublime';
cell.Cell.options_default.cm_config.extraKeys["Ctrl-Enter"] = function(cm) {}
var cells = IPython.notebook.get_cells();
for(var cl=0; cl< cells.length ; cl++){
cells[cl].code_mirror.setOption('keyMap', 'sublime');
cells[cl].code_mirror.setOption("extraKeys", {
"Ctrl-Enter": function(cm) {}
});
}
}
);
and restart jupyter. Now Ctrl+D should work like it does in Sublime.
You can see that Ctrl-Enter functionality is disabled as it would be very convenient to run current cell rather than creating new line for most users. You can choose to have that functionality by commenting that line out.
You can disable other key config that you don't want in a similar way.
Most recent (and easy) way
The best way right now to achieve Sublime-like keymapping in Jupyter Notebook: Select CodeMirror Keymap from jupyter-contrib-nbextensions. As reported in the homepage:
The jupyter_contrib_nbextensions package contains a collection of community-contributed unofficial extensions that add functionality to the Jupyter notebook.
I personally use several extensions from this package and I find them very useful.
As reported in the installation docs, you simply need to run:
pip install jupyter_contrib_nbextensions
to install the extensions (or better, I would suggest:
python -m pip install jupyter_contrib_nbextensions
where python points to the python executable of the installation you are using within Jupyter Notebook). You can also use conda if you prefer.
Anyway, you then need to copy some JS and CSS stuff to make the extensions work within Jupyter Notebook, which you can achieve through:
jupyter contrib nbextension install --user
again, assuming that jupyter points to the jupyter executable you are using to run your notebooks.
At this point, you simply need to enable the extension: navigate the nbextensions_configurator (that comes as a dependency with the jupyter_contrib_nbextensions package), which you can easily do through the Jupyter Notebook dashboard (to be clear, the page you open to run your notebooks) by browsing the Nbextensions tab and check the box corresponding to Select CodeMirror Keymap.
Done! Launching a notebook it will be sufficient to click on Edit>Keymaps>Sublime to achieve the desired behaviour.
I know this is a rather old question, but I happened to come across it before finding out about jupyter_contrib_nbextensions (and in particular the Select CodeMirror Keymap extension). Thus, I decided to post this answer, hopefully to help other people like me and to let them avoid some further search or messing up with customized JS files (which could scary someone).
In jupyter lab now you can add in the extension by searching sublime
Click install and rebuild jupyter.
**Notice: when you click install look at the terminal console, the building result will be shown there
The above solution worked for me, but I found that it had the undesirable effect of entering a "tab" character when I hit enter. Here is the associated GitHub issue: https://github.com/jupyter/notebook/issues/4769#issuecomment-511935127
Per that post, I found that this solution gives the right ctrl + d behavior, and keeps tabs-as-spaces.
require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
function(sublime_keymap, cell, IPython) {
// setTimeout(function(){ // uncomment line to fake race-condition
cell.Cell.options_default.cm_config.keyMap = 'sublime';
var cells = IPython.notebook.get_cells();
for(var c=0; c< cells.length ; c++){
cells[c].code_mirror.setOption('keyMap', 'sublime');
}
// }, 1000)// uncomment line to fake race condition
}
);
In Jupyter Lab, this can now be set in Settings > Text Editor Key Map > Sublime Text.
The only solution which made this work for me is
pip install jupyterlab_sublime

Sublime 3 not interfacing with R (tried R-box and REPL)

Super basic question here:
I installed the R-box package in Sublime 3 with no problems.
I changed the path to my R.app in the SublimeREPL.sublime-settings in Sublime, although this should not make a differece on Mac.
I checked in Package Control -> R-Box:Select Program. It's set to R.
I'm simply unable to get Sublime to send code to R. Pressing Cmd+Enter does nothing (actually, it starts a new line on Sublime).
I'm running Sublime 3 on Maverics, and R version 3.2.1. But I had the same problems with Sublime 2 and a previous R version. I'm sure I'm missing something simple but I can't find any more information in the installation page.
Open up an R console by pressing Ctrl+Shift+P and typing REPL R (after a few times you’ll be able to just type R and it will come up). You can open up two windows using (Alt+Shift+2) so you can have your R code on the left and your R console on the right.
As for running the code, once you have called the R console, you have three options: To run the current line or your selected lines, press Ctrl+Shift (release) then l. To run just the selected text, press Ctrl+Shift (release) then s. To run the entire file, press Ctrl+Shift (release) then f.
Actually, I got an answer from the R-box developers, that worked perfectly:
Close Sublime Text 3, then reopen it. Then check that at the bottom right of the window it says R Extended.
If not, you need to set the Syntax on the file:
cmd+shift+P
Set Syntax: R Extended

Issues with Revolution R Open + Yosemite + Sublime Text

I have installed RRO on a new macbook pro 13" retina (two cores) & Yosemite.
I tried with RSTUDIO and R 25 (S. Urbinek notorious benchmark) and I got the test time down from ~31 s to a blazing 5 s (thanks to multithreading and Intel MKL). Marvellous!
The problems are with Sublime text. I use Sublime text 3 as text console more often than rstudio for a variety of reasons.
I use it in conjunction with the package R-Box to drive where I want to send the code to: either to the R console, or with SublimeREPL R to direct the code to Sublime itself splitting the screen in two and sending the code to the right hand of the screen where I run the R console.
Normally I configure R-Box user settings with R, and SublimeREPL specifying the R path as /usr/bin/R (see below).
Results (sadly)
R-Box & R does not work: it cannot find the RRO app (even changing
the name of the app from RRO to R it does not find it).
R-Box & SublimeREPL (i.e. the
console in the right side of the screen) shows the console OK, but there is no
visible prompt, hence it is of no use.
These are the R scripts that work with CRAN R:
# R-Box
{
"App": "R",
"osx":
{
"App": "SublimeREPL"
}
}
# SublimeREPL
{
"default_extend_env": {"PATH": "{PATH};/usr/bin/R"},
"show_transferred_text": true
}
(I posted this also on the RRO forun at https://groups.google.com/forum/#!topic/rropen/bK_YPqxhXsI)
PS: could somebody with tagging power create a tag for RRO (Revolution R Open)?
The first issues with R-Box is resolved changing RRO app name to R.app (alias didn't work and I had explicitly to change the name of the app).
As in my comment above, the second issue with SublimeREPL is resolved changing the setting of
echo = true
in the file at ~/Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/R (otherwise set to false).
As the change it is not in a file "customisable" in the console one needs to probably change it at any new release of SublimeREPL.

Resources