Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history search backward in R

Tags:

r

Normally in my machine I can search R's history backwards by typing the desired first characters of the command I want to backward-search and then use the PageUp or PageDown keys to go through all the entries in the R history.

I am working as a guest in a remote cluster now and this option is not available in this machine.

Does anyone have an idea of where can I add this function to R?

EDIT: I am interested on key bindings rather than how to reproduce this function.

EDIT2: I am locally on a Fedora 16 machine; remotely CentOS release 5.3 (Final)

like image 922
pedrosaurio Avatar asked Oct 16 '12 13:10

pedrosaurio


2 Answers

history(pattern="lm\\(")   # finds lines with lm or glm calls

There are a variety of history mechanisms and it may be that what your console is looking at will not be the same as that which the history call will be accessing. Read the Details section of the ?history page.

like image 129
IRTFM Avatar answered Sep 20 '22 10:09

IRTFM


I found where to look at in order to tell R how to behave.

The key was to modify my ~/.inputrc file as it is the reference for R's input method.

I used the same file from my local Fedora 16 /etc/inputrc and copied it into the remote cluster as ~/.inputrc. The file looks like this

# do not bell on tab-completion
#set bell-style none

set meta-flag on
set input-meta on
set convert-meta off
set output-meta on

# Completed names which are symbolic links to
# directories have a slash appended.
set mark-symlinked-directories on

$if mode=emacs

# for linux console and RH/Debian xterm
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# commented out keymappings for pgup/pgdown to reach begin/end of history
#"\e[5~": beginning-of-history
#"\e[6~": end-of-history
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word

# for rxvt
"\e[8~": end-of-line
"\eOc": forward-word
"\eOd": backward-word

# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for freebsd console
"\e[H": beginning-of-line
"\e[F": end-of-line
$endif
like image 39
pedrosaurio Avatar answered Sep 24 '22 10:09

pedrosaurio