R syntax highlighting in Terminal - r

Can we get syntax highlighting for R in the Terminal?

I've finally found a library that meets my needs.
Now I'm much happier with my coding environment.
colorout is an R package that colorizes R output when running in a terminal emulator.The package cannot be on CRAN because it changes code already loaded by R and this is prohibited by the CRAN Repository Policy. The package replaces the functions that output results and messages to R Console, and this is necessary because we cannot colorize the output without replacing these functions. To install it, do the following in R:
install.packages("devtools")
devtools::install_github("jalvesaq/colorout")
library("colorout")
# do something

Use something like ess on emacs or RStudio for syntax highlighting for R instead of expecting it to work in the terminal.

Another option now would be to use radian instead of the default R prompt.

As hd1 indicated, this is not an R question. You're asking the OSX Terminal.app to do something it's not capable of. A quick look around Google (happy Zamboni birthday!) shows Vim syntax Highlighting for highlighting within vim , or https://superuser.com/questions/72057/terminal-emulator-with-custom-color-palette , but dunno if these will run under Darwin.
EDIT: I can't stay away from the search :-) . So check out these threads: https://superuser.com/questions/400360/syntax-highlighting-in-terminal-mac-os-x , http://forums.macrumors.com/showthread.php?t=412609 , and a recommendation to install zsh , https://apple.stackexchange.com/questions/12161/os-x-terminal-must-have-utilities

Related

Problem with find and replace in R Editor

I am currently using R (RGui; R version 4.2.1). I use 'find' and 'replace' in R Editor a lot. Recently, both will only work for one character. So I can find 'a' but it won't find any instances of 'aaa' even if I know they exist. I'd be really happy if anyone can suggest a solution as it's driving me crazy. Thanks!
This was recently fixed in Rgui for Windows. I am using "R version 4.2.1 Patched (2022-09-28 r82941 ucrt)" and it works (using ctrl-h or the Edit menu in the Rgui R Editor).
In the BUG FIXES on Windows subsection within the section CHANGES IN R 4.2.1 patched of https://cran.r-project.org/doc/manuals/r-devel/NEWS.html it says:
Find and replace operations work again in the script editor in Rgui on Windows.
Same problem - with R 4.2.1 I cannot find and replace using the R editor. I had to close the script up and do it in .txt.
I have the same issue. R version 4.2.1 on Windows 10. It doesn't find anything I search for, even if I can see it right there on the screen. Not even single-character strings. I was editing a non-R file.

Greek Characters in Julia Jupyter edition

I am using Julia.
I am trying to get some greek characters in Jupyter notebooks.
First I downloaded the latest version of Julia 1.6.2
For the jupyter connection I used anaconda, in julia repl i put ] add IJulia, and then I could chose the Julia kernel in Jupyter.
Then a friend suggested to download vs code (since we got a problem in the working directory with jupyter-anaconda)
In VS code we got no problem with working directories. And to work with notebooks we installed the Jupyter extension. It was working very well, but we got to this problem that we cannot get greek characters.
In Jupyter (anaconda) I could easily put greek characters, like this:
no package needed, nothing, just like that.
However in VSCode I cannot get that, nor "predictive text" or coding suggestions:
Any tips on how to solve this?
Like we are preferring VS Code and we know there's a way to get the greek characters on it, but we don't know how.
Any help is very welcomed.
Thanks in advance.
Check out the docs for the Julia extension in VS code here: https://code.visualstudio.com/docs/languages/julia. Per the comments above, make sure this is installed and you have the Julia kernel selected. You should then see the following:

Error with setwd in R

When trying to use the sample code for SubgraphMining (the example is on 35th page), I get an error:
"Error in setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining", :
cannot change working directory"
I'm using RStudio 0.97.551, 32-bit R (2.15.3 - this version of R was recommended to use with subgraphMining), igraph0 (was recommeded too, instead of igraph library), Java installed. Operation system is Windows 8.
Can anyone help me with the issue?
The error message is coming from the gspan function of subgraphMining, from here:
setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining",
"parsemis", sep = "\\"))
The reason for it is that R uses / as path separator, and not \\, which only works on windows. A workaround is not modify the function and use / instead of \\.
Btw. this has nothing to do with the igraph package, so I'll remove that tag.
In my case, it displayed the error because I expected it to create a new folder which I mentioned in the path in setwd. Unfortunately, R does not have this functionality and the matter was resolved when I created the folder and then used setwd command.
I know it's almost 1 year since this question was posted. I encountered the same problem with subgraphMining package. A quick hack is: You can write "gspan" on RStudio's command line and it will show the function, copy that function and create your own function in your own script (of course with new name, let's say gspanNew) and fix it by replacing "\\" with "/", as Gabor Csardi pointed out.
Cheers! :)
You can always use file.path("path","with","code") instead of simple paste in order for your code to be OS independent.

source code for autocompletion in R run in terminal

I would like to study the autocomplete code of R, when R is run in a terminal. For example, if you run R from the terminal and type lm( and then tab, R will give you the arguments of lm.
Dirk's answer here suggests that autocompletion of R is supported by the codetools package which is in base R:
Is it possible to get code completion for R in Emacs ESS similar to what is available in Rstudio?
However, I can't find where in that package it adds support for autocomplete. I grepped for 'completion' and came up empty.
The completion code is actually in the base instalation in the utils package. You can view everything associated with it (for the devel version) on R's SVN server:
http://svn.r-project.org/R/trunk/src/library/utils/R/completion.R
This code should be read in conjunction with ?completion.

vi input mode in R?

I'd like to be able to edit my R history using vi commands (e.g. ESC-/, ESC-k). I noticed a similar question here:
vi input mode in command line Matlab?
and tried the readline mods suggested in this post (doesn't R use readline?) but they don't work (for me).
Any ideas?
The Vim-R-plugin should do the trick. I have used it in Ubuntu, MacOS, and Windows 7. The developer is great and does frequent bugfixes.
To get Vim behavior in the R console you'll need to use the Conque Shell plugin, which Vim-R-plugin supports. I tried it for a day but found modality in the R command line a little tedious. All I ever use is tab completion and last command.

Resources