Using SuplimeREPL to run R - r

I'm using Sublime text 3, and I'm trying to get SublimeREPL to print R files output in the interactive mode that is already open, without reopen a new interactive session every time I modify the .r file and hit cmd + B
I followed sblair procedure for Python here and created R.sublime-build file with the following parameters:
{
"target": "run_existing_window_command",
"id": "repl_r",
"file": "config/R/Main.sublime-menu"
}
and modified a default line in Main.sublime-menu:
"osx": ["R", "--interactive", "--no-readline"]
into:
"osx": ["R", "--slave", "-f", "$file"]
Now every time I hit cmd + B, I get a new window, with the output by itself!
I couldn't figure out how to make the same window that runs the interactive session to print the output stay running
Note: I know that I can just switch to the prompt window and type >source("FILE")
every time I change something, but I want to know if there's a way as easy as making changes to .r file, hit some shortcut, voalla your output is in the same prompt window you were working on.

If i understand correctly..
Yep, there is, just bind "command": "repl_transfer_current", "args": {"scope": "file"} to a key and when you hit that key it will pass your current file to the REPL prompt for that file.
What i do, that is even better, i got:
{ "keys": ["super+r"], "command": "build" },
{ "keys": ["super+b"], "command": "repl_transfer_current", "args": {"scope": "file"} },
So i can build in the Sublime console with Cmd-R and in the REPL with Cmd-B.
Hope it helps!

Related

VS Code/R - how to paste highlighted text in editor to arguments in keyboard shortcut

I am regularly using the skimr::skim(name_of_a_dataframe) command in r when working interactively. To make the work a bit more efficient, I would like to assign the command to a keyboard shortcut which applies skimr::skim() to the text highlighted in the editor, i.e. the name of the dataframe. Essentially, the behavior should be similar to the keybinding F2 which opens the dataframe.
Here's what I came up with so far:
{
"key": "F7",
"description": "run skimr::skim() on df",
"command": "r.runCommand",
"when": "editorTextFocus",
"args": "skimr::skim(XXXX)"
}
The problem I am facing is this: How can I insert the text which I highlighted/selected in the editor paste into the args section of the keybinding (XXXX).
There is a related question on SO, but the solution is eventually a snippet, something I do not need. Many thanks.
Use the command r.runCommandWithSelectionOrWord and represent the selection or word under the cursor with $$:
{
"key": "F7",
"description": "run skimr::skim() on df",
"command": "r.runCommandWithSelectionOrWord",
"when": "editorTextFocus",
"args": "skimr::skim($$)"
}
Info about this and related commands is on the vscode-R Wiki here: https://github.com/REditorSupport/vscode-R/wiki/Keyboard-shortcuts#creating-keybindings-for-r-commands

R not showing in Terminal

I'm new to VS Code and am trying to use R there. I think I have it set-up correctly with all required sub-programs installed. When attempting to print "Hello World", the output tab produces messages that makes me think VS Code is recognizing the R code. Also, I can hover over my R code in VS Code and the hints pop up explaining the R functions; so I did something right I think.
I noticed that the bottom right of the VS Code screen says "R: (not attached)"
When I click on that and try to attach it, I get this:
PS C:\Users\Bob > .vsc.attach()
At line:1 char:13
+ .vsc.attach()
+ ~
An expression was expected after '('.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
In the terminal, if I click the down arrow next to Powershell, I get these options:
PowerShell(Default)
Command Prompt
JavaScipt Debug Terminal
Split Terminal
Configure Terminal Settings
Select Default Profile
To get to my JSON file, I go to View >> Command Pallette then type "Open Settings JSON". It contains this:
{
"workbench.colorTheme": "Default Light+",
"r.alwaysUseActiveTerminal": true,
"r.rpath.windows": "C:\\Program Files\\R\\R-4.1.2\\bin\\x64\\R.exe",
"security.workspace.trust.untrustedFiles": "open",
"files.associations": {
"*.R": "r"
},
"r.lsp.debug": true,
"r.rterm.windows": "C:\\Program Files\\R\\R-4.1.2\\bin\\x64\\R.exe",
"r.bracketedPaste": true,
"r.source.focus": "terminal",
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=C:\\Program Files\\R\\R-4.1.2\\bin\\R.exe"
],
"terminal.external.windowsExec": "C:\\Program Files\\R\\R-4.1.2\\bin\\R.exe"
}
I am not using radian right now. I want to get basic R working in VSCode then I'll connect with Radian.
It keeps trying to run my R script using PowerShell and I think this is the main problem. What do I do to get it to run using R? Thanks.
Based on what is in your JSON settings, it should work if you remove the \\x64 portion of your r.path.windows and r.term.windows paths:
"r.rpath.windows": "C:\\Program Files\\R\\R-4.1.2\\bin\\R.exe",
"r.rterm.windows": "C:\\Program Files\\R\\R-4.1.2\\bin\\R.exe",
// truncated
After changing that, you should be able to switch to an R terminal by using the drop-down menu in the terminal window.
Additionally, you can set R to be your default terminal by adding an additional line to your JSON Settings:
"terminal.integrated.defaultProfile.windows": "R",
// truncated

Is it possible to reopen running Sublime command console without hitting ctrl+B again (to prevent a new start)?

I run a code in sublime command console but accidentally pressed ctrl+f to find some text in the code. So the command console is replaced by search box. How can I make command console appear again without hitting ctrl+B as it will start a new code running? The code is run so far, I just want to continue it and need to see the progress is printed (I have the print line in the code) in console?
Just select Tools > Build Results > Show Build Results. You can also add a keybinding for it. E.g.
{
"keys": ["alt+b"],
"command": "show_panel",
"args": { "panel": "output.exec" },
},

Tmux-powerline status-interval make flicker

Mac OSX El Capitan
Tmux 1.9a
powerline https://github.com/erikw/tmux-powerline
Sometimes the status line flash, the segments will disappear and then appeare.
If I config the
set-option -g status-interval=5
it seems better but that is not the real time status .
Is that the normal phenomenon?
Or maybe I should do some config to avoid this.
It sounds like one of your segments is doing something that takes a long time to update. You can disable segments to see if that helps (configuration docs). The defaults are pretty expensive, and on my older MacBook, tmux regularly sits at 5% CPU or more. Disabling uptime and anything else you don't need might help.
Here's an example config where I trimmed some of the fat from the right status (removed uptime, system load, removed the seconds from the time). This goes in
~/.config/powerline/themes/tmux/default.json:
{
"segments": {
"right": [
{
"function": "powerline.segments.common.time.date"
},
{
"function": "powerline.segments.common.time.date",
"name": "time",
"args": {
"format": "%H:%M",
"istime": true
}
},
{
"function": "powerline.segments.common.net.hostname"
}
]
}
}
The default.json that ships with powerline is buried in the innards of the Python package, the location of which depends on how you installed it, your Python version, and other things (e.g. mine is at ~/.virtualenv/default/lib/python2.7/site-packages/powerline/config_files/themes/tmux/default.json). You can copy that to the ~/.config path above and modify it to your liking, or just use what I pasted.

How to pass a line to the console in sublime text 2 editor

I use RStudio for working with R programming language and find the ctrl+enter shortcut to send a line to the console extremely useful in troubleshooting my work.
Now I am using sublimetext2 and I would like to do the same thing in RStudio, send a line to the console.
Is there a way to send the existing line to the console or a SublimeREPL console?
I don't know about the console, but this is possible with SublimeREPL.
As long as you have a REPL and a file of the same language open at the same time, you can send a line (or a selection or file) to your open REPL via the SublimeREPL Source Buffer Keys. By default, Ctrl+, followed by l sends the current line to the REPL, but you can change the hotkey to Ctrl+Enter (in Python only, to protect other languages' default Ctrl+Enter functionality) by adding these lines to the top of your Preferences -> Key Bindings – User file:
{ "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.python", "match_all": true }
]
},
Other available scopes (from Preferences -> Browse Packages -> SublimeREPL/Default (Windows).sublime-keymap) are selection, file, and block (Clojure only). If you want to send a line to your REPL but not parse it immediately, you can add "action":"view_write" to the args object, like so:
{ "keys": ["ctrl+enter"], "command": "repl_transfer_current", "args": {"scope": "lines", "action": "view_write"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.python", "match_all": true }
]
},
See the Unofficial Sublime Text 2 Docs for more information on key bindings.
In the case that the REPL is open in a different tab than your source (rather than a separate view), the source buffer hotkeys will not focus the REPL. I'm sure it's possible to implement some sort of tab-swapping toggle key, but that sounds like a problem for another question.
In addition to setting up your own key bindings, you can simply install Enhanced-R:
In Sublime:
Cmd + Shift + P (to bring up the command palette)
type "Install Package"
Navigate to Enhanced-R
If you are using Sublime for mostly just R, then you can set the default syntax for the whole app. Or you can change it per file (Cmd + Shift + P again, then start typing Syntax Enhanced R)
Then, like you are used to in RStudio, you simply hit Cmd + enter to ship the code to the Console or R.app etc
Sending raw R code to SublimeREPL does work now:
Bring up the Cmd/Ctrl+Shift+P menu
Select R Application Switch
Select SublimeREPL
When you have SublimeREPL active, you'll be able to send raw R to it with Cmd/Ctrl+Enter.
Note that by default, SublimeREPL won't display the code that gets sent in; it'll just show you the output. If you want to also see the code, you can change your user settings:
Navigate to Preferences -> Package settings -> SublimeREPL -> Settings - User
Turn on the show_transferred_text setting.
For example, if you don't have any other settings, your settings should look like this:
{
"show_transferred_text": true
}

Resources