Skip to main content

A 21 century R console

Project description

radian: A 21 century R console

CircleCI Build status

radian is an improved console for the R program with multiline editing and rich syntax highlight and more ...

Under the hood, radian is built on top of the python library prompt-toolkit. One would consider radian as a ipython clone for R, though its layout and keybinds are actually more similar to those of julia.

radian is still under active developement, users should use it at their own risks.

Features

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

Installation

Requirements:

  • An installation of R (version 3.4.0 or above) is required to use radian, an R installation binary for your system can be downloaded from https://cran.r-project.org.
  • python is also required to install radian. If your system doesn't come with a python distribution, it can be downloaded from https://conda.io/miniconda.html. Both version 2 and version 3 should work, though python 3 is recommended.
  • pip is optional but it makes the installation a bit easier.
# install released version
pip install -U radian
# to run radian
radian
# or the development version
pip install -U git+https://github.com/randy3k/rchitect
pip install -U git+https://github.com/randy3k/lineedit
pip install -U git+https://github.com/randy3k/radian

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 tranditional R console. (R is still useful, e.g, running R CMD BUILD.)

Settings

radian can be customized via options in .Rprofile file. This file is usually located in your user home directory.

options(
    # see https://help.farbox.com/pygments.html
    # for a list of supported color schemes, default scheme is "native"
    radian.color_scheme = "native",

    # either  `"emacs"` (default) or `"vi"`.
    radian.editing_mode = "emacs",

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

    # auto match brackets and quotes
    radian.auto_match = FALSE,

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

    # pop up completion while typing
    radian.complete_while_typing = TRUE,
    # timeout in seconds to cancel completion if it takes too long
    # set it to 0 to disable it
    radian.completion_timeout = 0.05,

    # automatically adjust R buffer size based on terminal width
    radian.auto_width = TRUE,

    # insert new line between prompts
    radian.insert_new_line = TRUE,

    # when using history search (ctrl-r/ctrl-s in emacs mode), do not show duplicate results
    radian.history_search_no_duplicates = FALSE,

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

    # supress the loading message for reticulate
    radian.suppress_reticulate_message = FALSE,
    # enable reticulate prompt and trigger `~`
    radian.enable_reticulate_prompt = TRUE
)

FAQ

How to specify R_HOME location

If radian cannot locate the installation of R automatically. The best option is to expose the R binary to the system PATH variable.

On Linux/macOS, you could also export the environment variable R_HOME. For example,

$ export R_HOME=/usr/local/lib/R
$ radian

Note that it should be the path to R_HOME, not the path to the R binary. The folder should contain a file called COPYING. In some cases, you may need to futher specify LD_LIBRARY_PATH,

$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`R RHOME`/lib"
$ radian

If the shared library cannot be found, please make sure your R was installed with the shared library libR.so or libR.dylib or libR.dll. On Linux, the flag --enable-R-shlib may be needed when R is complied from the source.

reticulate prompt does not autocomplete

Make sure that jedi is installed

pip install jedi

Fail to load library

Some packages may not be loaded properly with radian but they work well with the bare R. The issue could be caused by several reasons, check #38 and #46. Open an issue if it still doesn't work.

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 launching 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 intialization error

SystemError: initialization of _heapq did not return an extension module

You would need to install this particular version of reticulate for now.

devtools::install_github("rstudio/reticulate#279")

Readline Error

libreadline.so.6: undefined symbol: PC

If you are using conda and encounter this error, it is likely because the readline from conda is bugged. Install it again via conda-forge.

conda install -c conda-forge readline=6.2
# or
conda upgrade -c conda-forge readline

setTimeLimit not working

radian utilizes the function setTimeLimit to set timeout for long completion. Users may notice that setTimeLimit is not working under the global environment. A workaround is to put the code inside a block or a function,

{
    setTimeLimit(1)
    while(1) {}
    setTimeLimit()
}

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"

Credits

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

Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radian-0.0.1.tar.gz (20.6 kB view details)

Uploaded Source

File details

Details for the file radian-0.0.1.tar.gz.

File metadata

  • Download URL: radian-0.0.1.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for radian-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2152837ac3d72bc9b523c5aa35679f15696785c1f48183a45a86845059a7315a
MD5 cb24b569043266f5a8594fa633111a34
BLAKE2b-256 6879083c46079eb01931558cbdeb9de8701e2382e0135c0dfc31594782fd0240

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page