• Stars
    star
    1,976
  • Rank 23,460 (Top 0.5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A 21 century R console

radian: A 21 century R console

Main codecov Conda version

radian is an alternative console for the R program with multiline editing and rich syntax highlight. One would consider radian as a ipython clone for R, though its design is more aligned to julia.

Features

  • cross platform, runs on Windows, macOS and Linux
  • shell mode: hit ; to enter and <backspace> to leave
  • reticulate python repl mode: hit ~ to enter
  • improved R prompt and reticulate python prompt
    • multiline editing
    • syntax highlight
    • auto completion (reticulate autocompletion depends on jedi)
  • unicode support
  • latex completion
  • auto matching parens/quotes.
  • bracketed paste mode
  • emacs/vi editing mode
  • automatically adjust to terminal width
  • read more than 4096 bytes per line

Installation

Requirements:

# install released version
pip3 install -U radian
# to run radian
radian
# or the development version
pip3 install -U git+https://github.com/randy3k/radian

Alternatively, if you use conda or miniconda,

conda install -c conda-forge radian

In this case, it is recommended to install R via conda to ensure consistency in C runtime libraries.

Alias on unix system

You could alias r to radian by putting

alias r="radian"

in ~/.bash_profile such that r would open radian and R would still open the traditional R console. (R is still useful, e.g, running R CMD BUILD.)

Settings

radian can be customized by specifying the below options in various locations

  • $XDG_CONFIG_HOME/radian/profile or $HOME/.config/radian/profile (Unix)
  • %USERPROFILE%/radian/profile (Windows)
  • $HOME/.radian_profile (Unix)
  • %USERPROFILE%/.radian_profile (Windows)
  • .radian_profile in the working directory

The options could be also specified in the .Rprofile files, however, it is not recommended because

  1. the settings are not persistent when vanilla mode is used;
  2. it doesn't work well with packrat or renv.
# Do not copy the whole configuration, just specify what you need!
# see https://help.farbox.com/pygments.html
# for a list of supported color schemes, default scheme is "native"
options(radian.color_scheme = "native")

# either  `"emacs"` (default) or `"vi"`.
options(radian.editing_mode = "emacs")
# enable various emacs bindings in vi insert mode
options(radian.emacs_bindings_in_vi_insert_mode = FALSE)
# show vi mode state when radian.editing_mode is `vi`
options(radian.show_vi_mode_prompt = TRUE)
options(radian.vi_mode_prompt = "\033[0;34m[{}]\033[0m ")

# indent continuation lines
# turn this off if you want to copy code without the extra indentation;
# but it leads to less elegent layout
options(radian.indent_lines = TRUE)

# auto match brackets and quotes
options(radian.auto_match = TRUE)

# enable the [prompt_toolkit](https://python-prompt-toolkit.readthedocs.io/en/master/index.html) [`auto_suggest` feature](https://python-prompt-toolkit.readthedocs.io/en/master/pages/asking_for_input.html#auto-suggestion)
# this option is experimental and is known to break python prompt, use it with caution
options(radian.auto_suggest = FALSE)

# highlight matching bracket
options(radian.highlight_matching_bracket = FALSE)

# auto indentation for new line and curly braces
options(radian.auto_indentation = TRUE)
options(radian.tab_size = 4)

# pop up completion while typing
options(radian.complete_while_typing = TRUE)
# the minimum length of prefix to trigger auto completions
options(radian.completion_prefix_length = 2)
# timeout in seconds to cancel completion if it takes too long
# set it to 0 to disable it
options(radian.completion_timeout = 0.05)
# add spaces around equals in function argument completion
options(radian.completion_adding_spaces_around_equals = TRUE)

# automatically adjust R buffer size based on terminal width
options(radian.auto_width = TRUE)

# insert new line between prompts
options(radian.insert_new_line = TRUE)

# max number of history records
options(radian.history_size = 20000)
# where the global history is stored, environmental variables will be expanded
# note that "~" is expanded to %USERPROFILE% or %HOME% in Windows
options(radian.global_history_file = "~/.radian_history")
# the filename that local history is stored, this file would be used instead of
# `radian.global_history_file` if it exists in the current working directory
options(radian.local_history_file = ".radian_history")
# when using history search (ctrl-r/ctrl-s in emacs mode), do not show duplicate results
options(radian.history_search_no_duplicates = FALSE)
# ignore case in history search
options(radian.history_search_ignore_case = FALSE)
# do not save debug browser commands such as `Q` in history
options(radian.history_ignore_browser_commands = TRUE)

# custom prompt for different modes
options(radian.prompt = "\033[0;34mr$>\033[0m ")
options(radian.shell_prompt = "\033[0;31m#!>\033[0m ")
options(radian.browse_prompt = "\033[0;33mBrowse[{}]>\033[0m ")

# stderr color format
options(radian.stderr_format = "\033[0;31m{}\033[0m")

# enable reticulate prompt and trigger `~`
options(radian.enable_reticulate_prompt = TRUE)

Custom key bindings

# allows user defined shortcuts, these keys should be escaped when send through the terminal.
# In the following example, `esc` + `-` sends `<-` and `ctrl` + `right` sends `%>%`.
# Note that in some terminals, you could mark `alt` as `escape` so you could use `alt` + `-` instead.
# Also, note that some ctrl mappings are reserved. You cannot remap m, i, h, d, or c
options(
    radian.escape_key_map = list(
        list(key = "-", value = " <- "),
    ),
    radian.ctrl_key_map = list(
        list(key = "right", value = " %>% ")
    )
)

FAQ

Unicode doesn't work in Windows and R 4.2+.

The latest version of R supports Unicode codepage directly. However, radian relies on Python and Python doesn't support Unicode in the way that R supports it. A workaround could be found here: #269 (comment)

I can't specify python runtime in reticulate.

It is expected. radian runs on python and the python runtime used by radian is forced in reticulate. reticulate::py_config() gives the note:

NOTE: Python version was forced by the current process

In order to use radian with another python runtime, you will need to install radian on that python environment.

How to switch to a different R or specify the version of R.

There are serveral options.

  • The easiest option is to pass the path to the R binary with --r-binary, i.e., radian --r-binary=/path/to/R
  • Also, one could expose the path to the R binary in the PATH variable
  • The environment variable R_BINARY could also be used to specify the path to R.
  • The environment variable R_HOME could also be used to specify R home directory. Note that it is should be set as the result of R.home(), not the directory where R is located. For example, in Unix
$ env R_HOME=/usr/local/lib/R radian

Cannot find shared library

Please also make sure that R was installed with the R shared library libR.so or libR.dylib or libR.dll. On Linux, the configure flag ./configure --enable-R-shlib may be needed to install R from the source. Do not forget to make clean to force the recompilation of the files with the correct compiler options.

Outdated setuptools

If you encounter

The package setup script has attempted to modify files on your system that are not within the EasyInstall build area.

Please update your setuptools by

pip install -U setuptools

How to use local history file

radian maintains its own history file .radian_history and doesn't use the .Rhistory file. A local .radian_history is used if it is found in the launch directory. Otherwise, the global history file ~/.radian_history would be used. To override the default behavior, you could launch radian with the options: radian --local-history, radian --global-history or radian --no-history.

Does it slow down my R program?

radian only provides a frontend to the R program, the actual running eventloop is the same as that of the traditional R console. There is no performance sacrifice (or gain) while using this modern command line interface.

Nvim-R support

Put

let R_app = "radian"
let R_cmd = "R"
let R_hl_term = 0
let R_args = []  " if you had set any
let R_bracketed_paste = 1

in your vim config.

reticulate Auto Completions

To enable reticulate prompt completions, make sure that jedi is installed.

pip install jedi

Alternatively, if you use conda,

conda install -c conda-forge jedi

Prompt not shown inside a docker container

It maybe caused by the invalid terminal size, try running stty size in your terminal to see if it returns a correct size. You could change the values of it from the environmental variables $COLUMNS and $LINES when you log-in the docker container.

docker exec -it <container> bash -c "stty cols $COLUMNS rows $LINES && bash"

Why called radian?

radian is powered by (Ο€)thon.

Credits

radian wouldn't be possible without the creative work prompt_toolkit by Jonathan Slenders.

More Repositories

1

Terminus

Bring a real terminal to Sublime Text
Python
1,382
star
2

AlignTab

An alignment plugin for Sublime Text using regular expression
Python
626
star
3

ProjectManager

Project Manager for Sublime Text
Python
323
star
4

SendCode

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, Terminus; R (RStudio), Julia, IPython.
Python
204
star
5

R-Box

R package for Sublime Text 3
Python
172
star
6

collections

High-performance container datatypes for R
R
102
star
7

remote-atom

rmate for atom
CoffeeScript
85
star
8

LaTeXYZ

Better LaTeX experience with Sublime Text
Python
74
star
9

AutoWrap

Auto (Hard) Wrap for Sublime Text 2/3
Python
63
star
10

arrangements

Fast Generators and Iterators of Permutations, Combinations and Partitions
R
52
star
11

rchitect

Interoperate R with Python
Python
51
star
12

LaTeXBox

A lightweight but deprecated LaTeX Plugin for Sublime Text 3
Python
46
star
13

Whitespace

Remove Trailing Whitespace for Sublime Text
Python
41
star
14

AutomaticPackageReloader

Automatically reload submodules while developing a Sublime Text package.
Python
37
star
15

shiny-cloudrun-demo

Running Shiny app on Google Cloud Run
R
34
star
16

UnitTesting-example

A getting started example for UnitTesting
Python
32
star
17

dotfiles

some of my dotfiles
Python
30
star
18

ChangeList

DEPRECATED: The missing Change List for Sublime Text 2/3 - History List, Last Edit ...
Python
30
star
19

SyntaxManager

Applying settings to a given syntax/extension
Python
29
star
20

homebrew-r

Homebrew formulas for R and related tools
Ruby
25
star
21

UnicodeCompletion

Insert Unicode LaTeX δ and Emoji 🍻 to Sublime Text
Python
24
star
22

LaTeXTab

Excel/CSV to LaTeX Table
Python
18
star
23

SendTextPlus

SendTextPlus is deprecated in favour of https://github.com/randy3k/SendCode
Python
17
star
24

otp

One Time Password Generation and Verification
R
16
star
25

retry

Repeated Evaluation
R
15
star
26

rpy2

Deprecated: use the official mirror: https://github.com/rpy2/rpy2
Python
15
star
27

xptr

Manipulating External Pointer
R
13
star
28

GitStatusBar

A more compact Git StatusBar
Python
13
star
29

rango

Calling R from Go and a better cli for the R console (WIP, nothing is working now)
Go
12
star
30

osascript

some useful apple scripts
AppleScript
9
star
31

iterpc

iterpc: deprecated in favour of https://github.com/randy3k/arrangements
R
9
star
32

sublime-default

Sublime Text 3 Default Package - This rpeo is outdated, check https://github.com/twolfson/sublime-files
Python
9
star
33

OpenHere

Open Finder, Terminal and iTerm in Sublime Text
AppleScript
5
star
34

GitHubChecks

Show GitHub checks result in Sublime Text
Python
5
star
35

sess

R
3
star
36

closure

Tools to create and manipulate closures
R
3
star
37

LSP-julia

Julia config for Sublime Text LSP
Python
3
star
38

netlify-deploystatus

JavaScript
3
star
39

random-scripts

some random scripts
Python
2
star
40

R-Extended

Improved R syntax files for Sublime Text
JavaScript
2
star
41

Keypress

Simulate Keypress in Sublime Text
Python
2
star
42

shiny-appengine-demo

Running Shiny app on Google App Engine
R
1
star
43

lineedit

lineedit: a readline library based on prompt_toolkit which supports multiple modes
Python
1
star
44

gh-actions

Shell
1
star
45

juliatalk

Jupyter Notebook
1
star
46

workbench

Bootstrapping my workbench on unix machines
Shell
1
star
47

randylai.info

source of randylai.info
HTML
1
star
48

UnitTesting-docker

Go to https://github.com/SublimeText/UnitTesting/tree/master/docker
Shell
1
star
49

ustring

Tools For Unicode Strings
R
1
star
50

RSpace

A Cocoa GUI for R on OSX
Objective-C
1
star
51

submit

A webapp for submitting project
HTML
1
star