Question

This question is about configuring the R console to behave like a bash shell when it comes to navigating the command history. It is somewhat related to the ?history. For brace-enclosed multi-lines, I'd like to configure the command history navigation of R to be similar to bash.

Presently when running R in an xterm under Linux, using the up-arrow to navigate the command history causes each previous line to be recalled one by one, even if a set of lines had been enclosed in braces. This occurs, for example, when copy/pasting a multi-line function from a text editor into the R console. Not so with bash. Here is an example of how bash functions in this regard:

In a bash shell within an xterm under Linux, after typing the following five lines...

a=1 
{
x=1
y=1
}

... the first press of the up-arrow will recall a single line reformulation of the brace-enclosed commands, like this ...

{ x=1; y=1; }

... and the second press will recall this ...

a=1

It seems that in R, the up-arrow navigates backwards one line at a time, regardless of encapsulation. Is there a way to configure R so that it's command history navigation functions like bash's?

No correct solution

OTHER TIPS

You could use rlwrap. I use it for other console programs and it works very well. You will need to prepend the R command with the rlwrap binary and then your history lines can be restored in a number of ways, including multi-line matching.

Workaround for Linux/Unix

Similarly as in Rstudio (thanks to Ari B. Friedman comment), where user in R console is using ShiftEnter to bypass RETURN, you can start newline (in R terminal) without accepting newline command using Ctrl-VCtrl-J. This way the multi-line command will be accepted into history as one-liner with line-feeds instead of enters and you will even have the chance to edit it. You can even manage in your .inputrc file to have custom combination for this action.

I do not think direct reconfiguration of R is possible.

Readline man page may help more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top