{"id":712,"date":"2011-01-15T16:17:21","date_gmt":"2011-01-15T21:17:21","guid":{"rendered":"http:\/\/lukemiller.org\/?p=712"},"modified":"2011-05-01T11:51:46","modified_gmt":"2011-05-01T15:51:46","slug":"a-lightweight-object-browser-for-r","status":"publish","type":"post","link":"https:\/\/lukemiller.org\/index.php\/2011\/01\/a-lightweight-object-browser-for-r\/","title":{"rendered":"A lightweight object browser for R"},"content":{"rendered":"<h6>The following post is based on information originally found here: <a href=\"http:\/\/r.789695.n4.nabble.com\/Object-Browser-td2594912.html\">http:\/\/r.789695.n4.nabble.com\/Object-Browser-td2594912.html<\/a><\/h6>\n<p>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&#8217;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 &#8220;object browser&#8221; window can be a godsend.<\/p>\n<p>Diehard R command line users just use the <code>ls()<\/code> command to list the objects in memory, and get a description of an object using the <code>str()<\/code> 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 <a href=\"http:\/\/www.walware.de\/goto\/statet\">Eclipse\/StatET<\/a> or <a href=\"http:\/\/sciviews.org\/SciViews-K\/\">Komodo\/SciViews-K<\/a>, and other solutions like <a href=\"http:\/\/rforge.net\/JGR\/\">JGR<\/a>, can provide you with a full time object browser window. But if you&#8217;d like a slightly more lightweight solution, the info below shows how to use the <strong><code>gWidgets<\/code><\/strong> R package to open an object browser window in your basic R console session.<\/p>\n<figure id=\"attachment_713\" aria-describedby=\"caption-attachment-713\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/01\/obrowser1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-713 \" title=\"ObjectBrowser1\" src=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/01\/obrowser1-300x129.png\" alt=\"\" width=\"300\" height=\"129\" srcset=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/01\/obrowser1-300x129.png 300w, https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/01\/obrowser1-1024x441.png 1024w, https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/01\/obrowser1.png 1117w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-713\" class=\"wp-caption-text\">The Object Browser window on the right was spawned by the gWidgets package command &quot;gvarbrowser&quot;. It displays a list of the objects currently in memory in the R console session on the left.<\/figcaption><\/figure>\n<p style=\"text-align: center;\">&nbsp;<\/p>\n<p>To get access to an object browser inside R, follow these steps (should work on Windows and Mac OS X):<\/p>\n<ol>1. Fire up a new R session.<\/ol>\n<ol>2. At the prompt, type <code>install.packages(\"RGtk2\")<\/code><br \/>\nR 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.<\/ol>\n<ol>3. Back in the R console, a message tells you must now restart R before proceeding. Typing <code>q()<\/code> at the prompt will quit R.<\/ol>\n<ol>4. Restart R.<\/ol>\n<ol>5. At the R prompt, type <code>install.packages(\"gWidgets\", dependencies = TRUE)<\/code><br \/>\nThis should download the gWidgets package and some additional Gtk2 packages that gWidgets uses to produce the object browser window.<\/ol>\n<p>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.<\/p>\n<ol>6. At the R prompt, type <code>library(gWidgets)<\/code><\/ol>\n<ol>7. Next type <code>options(guiToolkit = \"RGtk2\")<\/code> This tells R which toolkit you want to use for this session of R when you&#8217;re launching new GUI windows (like the object browser window you&#8217;ll create in the next step).<\/ol>\n<ol>8. Finally, type <code>gvarbrowser(container = gwindow(\"Object Browser\"))<\/code> This command launches the browser window and titles it &#8220;Object Browser&#8221;. You can give it whatever name you like, but you do need to include the container = gwindow(&#8221; &#8220;) call.<\/ol>\n<p>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 <code>lm<\/code> command), time series objects, functions, or just display everything.<\/p>\n<p>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&#8217;t appear to work, so you&#8217;ll need to go to the Filter menu in the Object Browser window and choose another filter type to update the object browser&#8217;s contents.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Get access to a simple object browser in R so that you can see what variables, data frames, model objects and other junk you have in memory currently. If you don&#8217;t want to install a full-fledged integrated development environment, this option may be for you.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[218],"tags":[14,54,53,56,55,57,7,58,15,8],"class_list":["post-712","post","type-post","status-publish","format-standard","hentry","category-r-project","tag-eclipse","tag-gtk","tag-gwidgets","tag-jgr","tag-komodo","tag-object-browser","tag-r","tag-r-project","tag-statet","tag-statistics"],"_links":{"self":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":16,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/712\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}