1

Possible Duplicate:
Retrieving Variable Declaration

I would like some way to search through the history of commands sent to R for a running session. This can be done in Bash using ctrl-r history search, and I find it extremely useful.

Is there a shortcut key in the R GUI IDE that does this? I've looked through changelogs and done some google searching, and I can't find it.

If not, is there a way outside of the R GUI IDE to extract this information? Possibly by searching through some sort of .Rhistory file maybe?

How are other R users accessing command history?

Community
  • 1
  • 1
Clayton Stanley
  • 7,513
  • 9
  • 32
  • 46
  • 1
    I use a full blown IDE (Eclipse) that keeps track of my commands in a script. You can try RStudio, ESS and Eclipse+StatET, among others. – Roman Luštrik Jan 15 '13 at 18:51
  • 1
    This was from the beginning a question about the R Mac GUI interface with R, and I wonder if the persons voting to close it are equipped to properly make this decision? – IRTFM Jan 16 '13 at 06:20

2 Answers2

2

In the R GUI there is is a discoverable side panel that appears to whichever side of the screen has the most space and it has the history entries displayed in a clickable manner. That panel is kbd-toggled with shift-cmd-H, and if opened that way will place the active cursor in an entry line. That line at the top of that panel accepts regex expressions that will limit the displayed lines to those that match. It's a bit confusing (to me anyway) that there are separate history files. The side panel like the R.app or R64.app uses a file named ".Rapp.history", while the regular history file that a Terminal R session would access has its expected name.

The icon that does the show/hide toggling is exposed to the toolbar item selection panel of the console, so I suspect it is exposed to AppleScript commands. I'm not a big user of AppleScript and that last part is a hunch more than a promise.

The MacOSX FAQ says R will accept Applescript delivered R commands.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Geez. Thanks! Missed seeing that icon.... – Clayton Stanley Jan 15 '13 at 20:42
  • This works fine, except that it's really awkward to yank a line from the history window and paste it somewhere. Do you have some sort of trick you've discovered to do that? I'm currently, hitting enter to send it to the command prompt, then moving my hand to the mouse (ugh), then selecting the line, then cmd-c, then cmd-v somewhere else. – Clayton Stanley Jan 16 '13 at 01:21
  • I'm not sure what you mean. Double-clicking on a line in the history panel pastes it to the console. If the focus is on a line, up and down-arrows work. Keying cmd-enter pastes a highlighted line to the console and runs it. I think this is all in the FAQ. – IRTFM Jan 16 '13 at 01:37
  • I just reread the FAQ. What the history window does have is quite nice. What I'm missing is how to take a command in the history window and copy it to the clipboard, so that I can paste it in a source code document (not in the console). – Clayton Stanley Jan 16 '13 at 03:49
  • 1
    After double_clicking on an item, ctrl-shift-A; cmd-C and it's in your clipboard. – IRTFM Jan 16 '13 at 05:57
  • Thanks. That was enough information for me to find out about the shift key as an option for selecting text alongisde a cursor movement in Cocoa. I did not know about that. btw, `ctrl-shift-A` didn't work for me, but `cmd-shift-left` did. `ctrl-a`, `ctrl-e`, etc. all work for me, just not the shift addition. But I can adjust, and start using cmd versions in Cocoa apps. – Clayton Stanley Jan 16 '13 at 06:07
  • ctrl-shft-A is working for me to select from the current cursor to the beginning of the current line in the GUI console, even on lines that are not active. – IRTFM Jan 16 '13 at 06:11
  • Strange. What GUI version, and OS X version, if you have the time? I'm just curious. Running OS X 10.6.8 and R64 2.15.2 here. – Clayton Stanley Jan 16 '13 at 06:12
  • It also might be an OS config issue, since ctrl-a works for me in TextWrangler, but not ctrl-shift-a. I'll do some googling. – Clayton Stanley Jan 16 '13 at 06:13
  • Prezactly the same versions. I run the R.app in my laptop, and that's where I am at the moment although was on my tower where I run R64.app when this thread started. At the moment : R.app GUI 1.53 (6335) i386-apple-darwin9.8.0. I was told by Simon Urbanel that ctrl-A is a Unix standard for select to beginning of line. I added the shift as an experiment and it works. – IRTFM Jan 16 '13 at 06:13
  • `ctrl-shift-a` works for me too now. I was using a VNC connection before, and although those three keys work independently across the connection, when combining them, they didn't work. When working on the machine natively, everything works as expected. – Clayton Stanley Jan 16 '13 at 19:29
1

What is available as a shortcut depends on what interface you are using. If you use the r terminal on windows (but not the GUI) then ctrl-r works like you describe.

One tool (though not as easy) that should work for all interfaces is to use the 'history' command. Y can type something like history(pat='plot') and the recent commands that included "plot" in them will be displayed and you can cut and paste to rerun the command of interest.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • They tagged it with OS X, and the `history` answer is in the duplicate I pointed to. – joran Jan 15 '13 at 20:01
  • That's not a actually a feature of the R terminal, it's a feature of the readline library that R is using. But it certainly works if you're working in that environment. I'm not, so the OS X answer is the one I accepted. – Clayton Stanley Jan 15 '13 at 20:43
  • I missed the OSX tag, sorry. But the idea that the interface is important still holds. Other problems on OSX seem to depend on which way R is run (no personal experiance, I am mostly trapped in the windows world). – Greg Snow Jan 15 '13 at 22:38