The following post is based on information originally found here: http://r.789695.n4.nabble.com/Object-Browser-td2594912.html
If you use the basic R GUI and you can manage to remember what sorts of objects you have in the workspace more than 5 seconds after you enter them, you’ve got a better short term memory than I do. But if you constantly lose track of what variables, data frames, model objects and so forth you have in your R session, a separate “object browser” window can be a godsend.
Diehard R command line users just use the ls()
command to list the objects in memory, and get a description of an object using the str()
command. But the rest of us mere mortals are much better off with a separate, persistent, window that contains a list of all of the objects currently in memory. A full-fledged IDE (integrated development environment) like Eclipse/StatET or Komodo/SciViews-K, and other solutions like JGR, can provide you with a full time object browser window. But if you’d like a slightly more lightweight solution, the info below shows how to use the gWidgets
R package to open an object browser window in your basic R console session.
To get access to an object browser inside R, follow these steps (should work on Windows and Mac OS X):
- 1. Fire up a new R session.
- 2. At the prompt, type
install.packages("RGtk2")
R will probably prompt you to choose a local mirror to download from. Choose one and watch the installation proceed. RGtk2 is a large package (10+ MB) that will take a while to download and install. You may need to click through the OS software installation windows that pop up to complete the installation.
- 3. Back in the R console, a message tells you must now restart R before proceeding. Typing
q()
at the prompt will quit R.- 4. Restart R.
- 5. At the R prompt, type
install.packages("gWidgets", dependencies = TRUE)
This should download the gWidgets package and some additional Gtk2 packages that gWidgets uses to produce the object browser window.
That marks the end of the initial installation. The following steps are what you type at the start of a normal R session to create the object browser window.
- 6. At the R prompt, type
library(gWidgets)
- 7. Next type
options(guiToolkit = "RGtk2")
This tells R which toolkit you want to use for this session of R when you’re launching new GUI windows (like the object browser window you’ll create in the next step).- 8. Finally, type
gvarbrowser(container = gwindow("Object Browser"))
This command launches the browser window and titles it “Object Browser”. You can give it whatever name you like, but you do need to include the container = gwindow(” “) call.At this point the Object Browser window should spawn. The top of the window has a pull-down menu to filter the objects displayed in the window. You can choose to display data sets (data frames, matrices, vectors), models (objects created from functions like the lm
command), time series objects, functions, or just display everything.
Under Windows 7, the object browser typically refreshes itself automatically, so that when you create a new object at the R command line, it shows up in the Object Browser window. Under Mac OS X you might get a few error messages on startup, and the auto-refresh doesn’t appear to work, so you’ll need to go to the Filter menu in the Object Browser window and choose another filter type to update the object browser’s contents.