R not showing in Terminal - r

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

Related

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" },
},

Building with meson/ninja takes multiple executions to complete

I'm trying to switch a project over to meson/ninja but it takes multiple executions of ninja to successfully complete, and at first glance it appears that the early failures are because of incomplete build steps that are supposed to precede it. The steps that seem out of order are usually while I'm calling a sed through custom_target to fix some auto generated output during the compile of a library (lib-b) that depends on another one (lib-a). This is essentially what I have for (lib-b):
lib_b = shared_library('lib-b-' + apiversion, lib_b_sources,
link_args: [ '-Wl,--version-script' ],
vala_header: 'lib-b.h',
vala_args: lib_b_vala_args,
vala_vapi: 'lib-b-#0#.vapi'.format(apiversion),
vala_gir: 'Lib-#0#.gir'.format(apiversion),
dependencies: lib_b_deps,
c_args: lib_b_args,
soversion: soversion,
install: true,
install_dir: [ true, true, true, false ],
)
custom_target('LibB-#0#.gir'.format(apiversion),
command: [ sed,
'-e', 's|Lib[.]|LibB.|g',
'-e', 's|namespace name="Lib"|namespace name="LibB"|g',
'-e', 's|LibB[.]Foo|LibA.Foo|g',
'-e', 's|<package name="lib-b-#0#"/>|<include name="LibA" version="#0#"/><package name="lib-b-#0#"/>|'.format(apiversion),
join_paths(meson.current_build_dir(), 'Lib-#0#.gir'.format(apiversion)),
],
output: 'LibB-#0#.gir'.format(apiversion),
capture: true,
install: true,
install_dir: dir_gir,
)
if g_ir_compiler.found()
custom_target('LibB-#0#.typelib'.format(apiversion),
command: [ g_ir_compiler,
'--shared-library', lib_b.full_path(),
'--includedir', lib_a_girdir,
'--output', '#OUTPUT#',
join_paths(meson.current_build_dir(), 'LibB-#0#.gir'.format(apiversion)),
],
output: 'LibB-#0#.typelib'.format(apiversion),
depends: lib_b,
install: true,
install_dir: dir_typelib,
)
endif
After the first run of ninja I get errors like this:
FAILED: src/lib/b/LibB-1.0.gir
/usr/bin/python3 /usr/bin/meson --internal exe /home/user/proj/_build/meson-private/meson_exe_sed_3429069bbdfaffa2d113b782ce02a55d5fd96973.dat
/usr/bin/sed: can't read /home/user/proj/_build/src/lib/b/Lib-1.0.gir: No such file or directory
Where Lib-1.0.gir is supposed to be one of the outputs of the shared_library command. If I run it again it creates the file, makes it further, and complains with a similar error. I run it again, further this time but errors on other internal projects that depend on the file that isn't being created. I run it one last time and it completes.
It would surprise me if meson/ninja was not capable to executing build steps in a sequence where one must precede the other. Have I done something gross/stupid here? I'm basically porting over an autotools setup that works, but is slooooow.
You have to put outputs into the input keyword of your custom_target's so they understand the dependency and run in the correct order.
Also you should be using the gnome module to generate gir files: http://mesonbuild.com/Gnome-module.html#gnomegenerate_gir

R calls mGENOVA-an external Program

Recently I have been trying to use R to call a .exe program named mGenov It's command line program. I have some screenshots to help me explain this (I use Windows 10).
Supposedly, it works this way:
double click on mGenova,
type card.txt
hit "enter" the cmd window will close
I have tried a lot; basically they can invoke the program, but pass the command about typing card.txt in the command
shell(cmd="D:\\mgenova\\mGENOVA\\card.txt", shell="D:\\mgenova\\mGENOVA\\mGENOVA.exe",intern=F)
OR
system("\"D:\\mgenova\\mGENOVA\\mGENOVA.exe\" \"D:\\mgenova\\mGENOVA\\card.txt\""
,show.output.on.console=TRUE,invisible=T,intern=T)
And I always got this
[1] "Input the filename containing the control cards." "" "" "*** Control cards file is empty"
attr(,"status")
[1] 1
Warning message:
running command '"D:\mgenova\mGENOVA\mGENOVA.exe" "D:\mgenova\mGENOVA\card.txt"' had status 1
How can I get it run on it? Thanks for helping!!!!!
You could create a batchfile (let's name it batch.bat) on Windows with the content
cd /D D:\mgenova\mGENOVA\
mGENOVA.exe < card.txt
All necessary input for GENOVA must be provided by the file card.txt.
Then in R run the command
system("batch.bat")

Run bash command for currently selected line

I'd like to be able to hit a shortcut like cmd-shift-r and have that automatically run a bash command, say, mix test test/turtle/api/v3_test.exs:72.
In other words: mix test {FILE_ACTIVE}:{FILE_ACTIVE_LINE_NUMBER}
What is the best way to accomplish this? Is there an atom package that takes care of this or something I could write quickly myself?
Thanks!
There is a fairly low-fi way to get this to work using your init.coffee load this by going to File → Init Script... or by choosing Application: Open Your Init Script from the Command Palette.
Add the following to the bottom of your init.coffee:
atom.commands.add 'atom-text-editor',
'custom:execute-this-test': ->
if editor = atom.workspace.getActiveTextEditor()
row = editor.getCursors()[0].getBufferRow() + 1
path = editor.buffer.file.path
{spawn} = require 'child_process'
mix = spawn 'mix', ['test', "#{path}:#{row}"]
mix.stderr.on 'data', (data) ->
atom.notifications.addError data.toString()
mix.stdout.on 'data', (data) ->
atom.notifications.addInfo data.toString()
mix.on 'exit', (code) ->
atom.notifications.addInfo "Exited with Code #{code}"
Save the file with Ctrl-S and reload the text editor with Ctrl-Alt-R.
Once Atom has restarted, find the line in the file you want to execute the code against and open the Command Palette with Ctrl-Shift-P and search for Execute This Test.
You may want to tweak the code to be reduce the amount of output it generates, however the above is probably enough to get you started. If you wanted to optimize the workflow even further you can create a Keybinding.

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