Skip to content

Instantly share code, notes, and snippets.

@myuhe
Created March 10, 2010 07:44
Show Gist options
  • Save myuhe/327649 to your computer and use it in GitHub Desktop.
Save myuhe/327649 to your computer and use it in GitHub Desktop.
anything-c-source-R-pkg
(defun anything-ess-marked-install (candidate)
(dolist (i (anything-marked-candidates))
(ess-execute (concat "install.packages(\"" i "\")\n") t)))
(defun anything-ess-marked-remove (candidate)
(dolist (i (anything-marked-candidates))
(ess-execute (concat "remove.packages(\"" i "\")\n") t)))
(setq anything-c-source-R-localpkg
'((name . "R-local-packages")
(init . (lambda ()
;; this grabs the process name associated with the buffer
(setq anything-c-ess-local-process-name ess-local-process-name)
;; this grabs the buffer for later use
(setq anything-c-ess-buffer (current-buffer))))
(candidates . (lambda ()
(let (buf)
(condition-case nil
(with-temp-buffer
(progn
(setq buf (current-buffer))
(with-current-buffer anything-c-ess-buffer
(ess-command "writeLines(paste('', sort(.packages(all.available=TRUE)), sep=''))\n" buf))
(split-string (buffer-string) "\n" t)))
(error nil)))))
(action
("load packages" . (lambda(obj-name)
(ess-execute (concat "library(" obj-name ")\n") t )))
("remove packages" . (lambda(obj-name)
(ess-execute (concat "remove.packages(\"" obj-name "\")\n") t)))
("remove marked packages" . anything-ess-marked-remove))
(volatile)))
(setq anything-c-source-R-repospkg
'((name . "R-repos-packages")
(init . (lambda ()
;; this grabs the process name associated with the buffer
(setq anything-c-ess-local-process-name ess-local-process-name)
;; this grabs the buffer for later use
(setq anything-c-ess-buffer (current-buffer))))
(candidates . (lambda ()
(let (buf)
(condition-case nil
(with-temp-buffer
(progn
(setq buf (current-buffer))
(with-current-buffer anything-c-ess-buffer
(ess-command "writeLines(paste('', rownames(available.packages(contriburl=contrib.url(\"http://cran.md.tsukuba.ac.jp/\"))), sep=''))\n" buf))
;; (ess-command "writeLines(paste('', sort(.packages(all.available=TRUE)), sep=''))\n" buf))
(split-string (buffer-string) "\n" t)))
(error nil)))))
(action
("install packages" . (lambda(obj-name)
(ess-execute (concat "install.packages(\"" obj-name "\")\n") t)))
("install marked packages" . anything-ess-marked-install))
(volatile)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment