Using gedit or Rgeidt with R

Editor for R statistical package
R and Rgedit in Ubuntu 9.10
Image created by Enayetur Raheem

Recently I've made the switch from Windows Vista to Ubuntu Linux. After switching, the first thing I needed was an editor for R package. R is my favourite and most-used environment for statistical computing. It is free and simple yet a very powerful tool for simple to high profile statistical computing.

I have done a small research on this and found several candidate software. Emacs and ESS (Emacs Speaks Statistics) turned up with maximum hits when I searched in Google. Most frequent R-users rely upon Emacs and ESS (Emacs Speaks Statistics) for obvious reasons. I will review Emacs and ESS in a separate post. In this post, I will limit discussing about using gedit and Rgedit as a frontend for R statistical package.

gedit is the default text editor in Gnome environment in Linux. And gedit has a simple but very useful plugin called Rgedit that makes it an excellent IDE for R. Of the many features of Rgedit, here I list only a few.

  1. It splits the window into two panes, and runs R in the bottom panel (can be set as visible or hidden using the Ctrl+F9 key. Default is hidden. This pane is detachable too :) )
  2. Out of the box syntax highlighting with or without the .R extension
  3. Single line code-processing or processing in blocks or the entire file
  4. Multiple R workspace can be run simultaneously (Shortcut: Shift+Ctrl+S)
  5. Customisable shortcut keys

Installation of Rgedit

Download and extract from http://sourceforge.net/projects/rgedit/
The detailed instructions are available in the Readme.txt file. I am copying from it:

To install, extract the RgeditXX.tar.bz2 archive somewhere and copy the contents of the resulting folder into to your ~/.gnome2/gedit/plugins folder (please note the "." dot; create this folder if necessary). Now, your ~/.gnome2/gedit/plugins folder should also contain:

RCtrl <- this is a folder
RCtrl.gedit-plugin
RCtrl.preferences
RCtrl.py
ReadMe.txt <- this ReadMe.txt file

Then activate the "R integration" plug-in from gedit (Go to Edit > Preferences > Plugins, and activate the 'R Integration' plugin)

Syntax Highlighting

If you are searching for "syntax highlighting for R" then find no more. Its there in gedit. All you need is to enable the options when you use gedit.

RGedit syntax highlighting in R

Shortcut Keys

One of the nice features of RGedit/gedit is that you can define your keyboard shortcuts yourself. Its built in shortcuts are also very intuitive. Some of them are listed below:

To define custom shortcuts, open gedit and from the menu, go to R > Configure R Interface > Edit Keyboard Shortcuts. I've defined two new shortcuts, (i) Shift+Alt+S to open a new R session, (ii) Shift+Alt+Q to close an R session. See the keyboard shortcut configuration screenshot below.

Keyboard shotcut keys for Rgedit

Example of shortcut keys with Rgedit

  1. Start gedit either from the terminal or from Applications > Accessories > gedit Text Editor
  2. Start an R session : Shift+Crtl+S
  3. Make the R workspace visible at the bottom of the gedit panel: Ctrl+F9
  4. Enter a code on the upper panel and press Shift+Ctrl+R to run that line
  5. To run several lines of code together, select lines and press Shift+Ctrl+E

Some must-have plugins for gedit

The default gedit comes with a few plugins. If you are using gedit for editing/writing and managing R codes, then you need the following plugins.

  1. Code Comment: To insert and remove comments in your R code [Shortcuts: Crtl+M to comment and Shift+Ctrl+M to remove comment]
  2. Bracket Completion: To automatically complete ending bracket.

How to get these extra plugins?
If you are using Ubuntu Linux, go to a Terminal and type the following at the prompt:

sudo apt-get install gedit-plugins

After installing, open gedit, and enable the plugins from Edit > Preferences > Plugins


Comments

Re: Using gedit or Rgeidt with R

Hey man!
Nice posting. I am using RGedit, and just added code comment / bracket completion! Thanks a lot.
Do you know if it is possible to add a function recognition (highlighting ) functionality on GEdit?
thanks!
drp

Re: Using gedit or Rgeidt with R

Thanks!
I did not explore that yet. If I know, I will post here as a comment. If you find by then, please do let me know. Thanks in advance.

Re: Using gedit or Rgeidt with R

I could not find the highlighting functionality yet, but code-folding for GEdit is very useful:
http://code.google.com/p/gedit-folding/
Let me know if you find something! :)
Thank you, drp

Re: Using gedit or Rgeidt with R

Not sure this is what you meant, but View -> Highlight mode -> Scientific -> R

Re: Using gedit or Rgeidt with R

By that I meant how to enable syntax highlighting for R in gedit.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • LaTex commands embedded in text will be interpreted and rendered. Additional information can be found at DruTex Documentation Pages
    • Assists automatic numbering of tex, equation, and equations environments.
    • Provides different environments to create rendered images (especially maths).
    • You may use <swf file="song.mp3"> to display Flash files inline
    • You can use BBCode tags in the text.

    More information about formatting options