problems with menus

John Fox jfox at mcmaster.ca
Mon Nov 11 04:23:41 CET 2002


Dear ESS list members,

I've been trying to add a menu that manages R packages, and I've hit a 
couple of snags. I'm using ESS and XEmacs with R under Windows 2000. I've 
appended the code, which is part of my init.el file, below. The menu is 
meant to work only with Windows. The problems are as follows:

(1) You'll see that I'm defining several menu items -- to load a package, 
to install a package from CRAN, etc. The code is similar to that provided 
by rgui.exe for Windows. All of the menu items appear to work fine, with 
the following exception: the "Load package" item only works when another 
menu item has previously been selected. That is, if "Load package" is the 
first menu item to be selected, the associated command appears to be 
entered properly into the R-process buffer, but nothing happens. If another 
menu item is selected first -- say, "Update packages from CRAN" -- this 
works properly, and then "Load package" also works if selected 
subsequently. To narrow down the problem further, I found that the R 
function select.list() does not bring up a dialog box, as it should, the 
first time that it is called. (Nevertheless, the menu item "Install package 
from CRAN" works fine, even if it is the first item selected and even 
though it calls select.list -- confusing!)

(2) I'd really prefer to add these menu items to the ESS menu, as 
submenu-items off a Packages item, but I haven't been able to figure out 
how to do this. I see how the ESS menu is defined in the file ess-model.el, 
but I can't find a hook to add items to this menu. Is this possible?

Any help would be appreciated.

Thanks,
  John

------------------------------------------  snip 
--------------------------------------------
;;; Add an R-Packages menu

(defun menu-load-package ()
   "Load package from a library."
   (interactive)
   (select-window win2)
   (ess-eval-linewise
     "{pkg <- select.list(sort(.packages(all.available = TRUE))); 
if(nchar(pkg)) library(pkg, character.only=TRUE)}\n")
   (comint-show-maximum-output)
   (select-window win1))

(defun menu-install-package-CRAN ()
   "Install package from CRAN."
   (interactive)
   (select-window win2)
   (ess-eval-linewise
     "{a <- CRAN.packages(); install.packages(select.list(a[,1],,TRUE), 
.libPaths()[1], available=a)}\n")
   (comint-show-maximum-output)
   (select-window win1))

(defun menu-install-package-zip ()
   "Install package from local zip file."
   (interactive)
   (select-window win2)
   (let ((file (string-replace
            (expand-file-name
         (read-file-name "Select zip file to install: " nil nil t))
            "\\" "/" 'all 0)))
     (ess-eval-linewise
      (concat "install.packages('" file "', .libPaths()[1], CRAN = NULL)\n")))
   (comint-show-maximum-output)
   (select-window win1))

(defun menu-update-packages ()
   "Update packages from CRAN"
   (interactive)
   (select-window win2)
   (ess-eval-linewise
     "update.packages()\n")
   (comint-show-maximum-output)
   (select-window win1))

(add-menu-item '("R-Packages") "Load package" 'menu-load-package t)
(add-menu-item '("R-Packages") "Install package from CRAN" 
'menu-install-package-CRAN t)
(add-menu-item '("R-Packages") "Install package from local zip file" 
'menu-install-package-zip t)
(add-menu-item '("R-Packages") "Update packages from CRAN" 
'menu-update-packages t)




-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
ess-help mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: ess-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the ESS-help mailing list