(ess-message "[ess-r-d:] (require 'ess-s-l)")
(require 'ess-s-l)
(require 'eldoc)
(require 'ess-r-args)
(require 'ess-developer)
(require 'ess-help)
(require 'ess-roxy)
(when (featurep 'emacs)
(require 'ess-tracebug))
(require 'compile)
(require 'easymenu)
(autoload 'ess-help-underline "ess-help" "(Autoload)" t)
(autoload 'ess--flush-help-into-current-buffer "ess-help" "(Autoload)" t)
(defvar ess-dev-map
(let (ess-dev-map)
(define-prefix-command 'ess-dev-map)
(define-key ess-dev-map "\C-t" 'ess-toggle-developer)
(define-key ess-dev-map "t" 'ess-toggle-developer)
(define-key ess-dev-map "T" 'ess-toggle-tracebug)
(define-key ess-dev-map "\C-a" 'ess-developer-add-package)
(define-key ess-dev-map "a" 'ess-developer-add-package)
(define-key ess-dev-map "\C-r" 'ess-developer-remove-package)
(define-key ess-dev-map "r" 'ess-developer-remove-package)
(define-key ess-dev-map "\C-l" 'ess-developer-load-package)
(define-key ess-dev-map "l" 'ess-developer-load-package)
(define-key ess-dev-map "`" 'ess-show-traceback)
(define-key ess-dev-map "~" 'ess-show-call-stack)
(define-key ess-dev-map "\C-w" 'ess-watch)
(define-key ess-dev-map "w" 'ess-watch)
(define-key ess-dev-map "\C-d" 'ess-debug-flag-for-debugging)
(define-key ess-dev-map "d" 'ess-debug-flag-for-debugging)
(define-key ess-dev-map "\C-u" 'ess-debug-unflag-for-debugging)
(define-key ess-dev-map "u" 'ess-debug-unflag-for-debugging)
(define-key ess-dev-map [(control ?D)] 'ess-debug-unflag-for-debugging)
(define-key ess-dev-map "\C-b" 'ess-bp-set)
(define-key ess-dev-map "b" 'ess-bp-set)
(define-key ess-dev-map [(control ?B)] 'ess-bp-set-conditional)
(define-key ess-dev-map "B" 'ess-bp-set-conditional)
(define-key ess-dev-map "\C-L" 'ess-bp-set-logger)
(define-key ess-dev-map "L" 'ess-bp-set-logger)
(define-key ess-dev-map "\C-o" 'ess-bp-toggle-state)
(define-key ess-dev-map "o" 'ess-bp-toggle-state)
(define-key ess-dev-map "\C-k" 'ess-bp-kill)
(define-key ess-dev-map "k" 'ess-bp-kill)
(define-key ess-dev-map "\C-K" 'ess-bp-kill-all)
(define-key ess-dev-map "K" 'ess-bp-kill-all)
(define-key ess-dev-map "\C-n" 'ess-bp-next)
(define-key ess-dev-map "n" 'ess-bp-next)
(define-key ess-dev-map "i" 'ess-debug-goto-input-event-marker)
(define-key ess-dev-map "I" 'ess-debug-goto-input-event-marker)
(define-key ess-dev-map "\C-p" 'ess-bp-previous)
(define-key ess-dev-map "p" 'ess-bp-previous)
(define-key ess-dev-map "\C-e" 'ess-debug-toggle-error-action)
(define-key ess-dev-map "e" 'ess-debug-toggle-error-action)
(define-key ess-dev-map "0" 'ess-electric-selection)
(define-key ess-dev-map "1" 'ess-electric-selection)
(define-key ess-dev-map "2" 'ess-electric-selection)
(define-key ess-dev-map "3" 'ess-electric-selection)
(define-key ess-dev-map "4" 'ess-electric-selection)
(define-key ess-dev-map "5" 'ess-electric-selection)
(define-key ess-dev-map "6" 'ess-electric-selection)
(define-key ess-dev-map "7" 'ess-electric-selection)
(define-key ess-dev-map "8" 'ess-electric-selection)
(define-key ess-dev-map "9" 'ess-electric-selection)
(define-key ess-dev-map "?" 'ess-tracebug-show-help)
ess-dev-map)
"Keymap for commands related to development and debugging.")
(easy-menu-define ess-roxygen-menu nil
"Roxygen submenu."
'("Roxygen"
:visible (and ess-dialect (string-match "^R" ess-dialect))
["Update/Generate Template" ess-roxy-update-entry t]
["Preview Rd" ess-roxy-preview-Rd t]
["Preview HTML" ess-roxy-preview-HTML t]
["Preview text" ess-roxy-preview-text t]
["Hide all" ess-roxy-hide-all t]
["Toggle Roxygen Prefix" ess-roxy-toggle-roxy-region t]))
(easy-menu-define ess-tracebug-menu nil
"Tracebug submenu."
'("Tracebug"
:visible (and ess-dialect (string-match "^R" ess-dialect))
["Active?" ess-toggle-tracebug
:style toggle
:selected (or (and (ess-process-live-p)
(ess-process-get 'tracebug))
ess-use-tracebug)]
["Show traceback" ess-show-traceback (ess-process-live-p)]
["Show call stack" ess-show-call-stack (ess-process-live-p)]
["Watch" ess-watch (and (ess-process-live-p)
(ess-process-get 'tracebug))]
["Error action cycle" ess-debug-toggle-error-action (and (ess-process-live-p)
(ess-process-get 'tracebug))]
"----"
["Flag for debugging" ess-debug-flag-for-debugging ess-local-process-name]
["Unflag for debugging" ess-debug-unflag-for-debugging ess-local-process-name]
"----"
["Set BP" ess-bp-set t]
["Set conditional BP" ess-bp-set-conditional t]
["Set logger BP" ess-bp-set-logger t]
["Kill BP" ess-bp-kill t]
["Kill all BPs" ess-bp-kill-all t]
["Next BP" ess-bp-next t]
["Previous BP" ess-bp-previous t]
"-----"
["About" ess-tracebug-show-help t]))
(easy-menu-define ess-developer-menu nil
"Developer submenu."
'("Developer"
:visible (and ess-dialect (string-match "^R" ess-dialect))
["Active?" ess-toggle-developer
:style toggle
:selected ess-developer]
["Add package" ess-developer-add-package t]
["Remove package" ess-developer-remove-package t]))
(easy-menu-add-item ess-mode-menu nil ess-roxygen-menu "end-dev")
(easy-menu-add-item ess-mode-menu nil ess-developer-menu "end-dev")
(easy-menu-add-item ess-mode-menu nil ess-tracebug-menu "end-dev")
(easy-menu-add-item inferior-ess-mode-menu nil ess-developer-menu "end-dev")
(easy-menu-add-item inferior-ess-mode-menu nil ess-tracebug-menu "end-dev")
(setq R-syntax-table S-syntax-table)
(modify-syntax-entry ?` "\"" R-syntax-table)
(modify-syntax-entry ?_ "_" R-syntax-table)
(ess-message "[ess-r-d:] (autoload ..) & (def** ..)")
(defvar R-customize-alist
(append
'((ess-local-customize-alist . 'R-customize-alist)
(ess-eldoc-function . 'ess-R-eldoc-function)
(ess-dialect . "R")
(ess-suffix . "R")
(ess-ac-sources . '(ac-source-R))
(ess-build-tags-command . "rtags('%s', recursive = TRUE, pattern = '\\\\.[RrSs](rw)?$',ofile = '%s')")
(ess-traceback-command . "local({cat(geterrmessage(), \"---------------------------------- \n\", fill=TRUE);try(traceback(), silent=TRUE)})\n")
(ess-call-stack-command . "traceback(1)\n")
(ess-eval-command . ".ess.eval(\"%s\", FALSE, FALSE, file=\"%f\")\n")
(ess-eval-visibly-command . ".ess.eval(\"%s\", TRUE, TRUE, 300, file=\"%f\")\n")
(ess-eval-visibly-noecho-command . ".ess.eval(\"%s\", FALSE, TRUE, 300, file=\"%f\")\n")
(ess-load-command . ".ess.source(\"%s\", FALSE, FALSE)\n")
(ess-load-visibly-command . ".ess.source(\"%s\", TRUE, TRUE, 300)\n")
(ess-load-visibly-noecho-command . ".ess.source(\"%s\", FALSE, TRUE, 300)\n")
(ess-dump-filename-template . (ess-replace-regexp-in-string
"S$" ess-suffix
ess-dump-filename-template-proto))
(ess-help-web-search-command . 'ess-R-sos)
(ess-mode-syntax-table . R-syntax-table)
(ess-mode-editing-alist . R-editing-alist)
(ess-change-sp-regexp . ess-R-change-sp-regexp)
(ess-help-sec-regex . ess-help-R-sec-regex)
(ess-help-sec-keys-alist . ess-help-R-sec-keys-alist)
(ess-loop-timeout . ess-S-loop-timeout)
(ess-cmd-delay . ess-R-cmd-delay)
(ess-function-pattern . ess-R-function-pattern)
(ess-object-name-db-file . "ess-r-namedb.el" )
(ess-smart-operators . ess-R-smart-operators)
(inferior-ess-program . inferior-R-program-name)
(inferior-ess-objects-command . inferior-R-objects-command)
(inferior-ess-font-lock-keywords . 'inferior-R-font-lock-keywords)
(inferior-ess-search-list-command . "search()\n")
(inferior-ess-help-command . inferior-ess-r-help-command)
(inferior-ess-help-filetype . nil)
(inferior-ess-exit-command . "q()")
(inferior-ess-exit-prompt . "Save workspace image? [y/n/c]: ")
(inferior-ess-start-file . nil)
(inferior-ess-start-args . "")
(ess-error-regexp-alist . ess-R-error-regexp-alist)
(ess-describe-object-at-point-commands . 'ess-R-describe-object-at-point-commands)
(ess-STERM . "iESS")
(ess-editor . R-editor)
(ess-pager . R-pager)
(prettify-symbols-alist . '(("<-" . ?←)
("<<-" . ?↞)
("->" . ?→)
("->>" . ?↠))))
S-common-cust-alist)
"Variables to customize for R -- set up later than emacs initialization.")
(defvar R-editing-alist
(let ((S-alist (copy-alist S-editing-alist)))
(setcdr (assoc 'ess-font-lock-defaults S-alist)
'(ess--extract-default-fl-keywords ess-R-font-lock-keywords))
(setcdr (assoc 'ess-font-lock-keywords S-alist)
(quote 'ess-R-font-lock-keywords))
S-alist)
"General options for editing R source files.")
(defvar ess-R-error-regexp-alist '(R R1 R2 R3 R4 R-recover)
"List of symbols which are looked up in `compilation-error-regexp-alist-alist'.")
(add-to-list 'compilation-error-regexp-alist-alist
'(R "\\(at \\(.+\\)#\\([0-9]+\\)\\)" 2 3 nil 2 1))
(add-to-list 'compilation-error-regexp-alist-alist
'(R1 " \\([^ \t\n]+\\)#\\([0-9]+\\)[: ]" 1 2 nil 2))
(add-to-list 'compilation-error-regexp-alist-alist
'(R2 "(\\(\\w+ \\([^())\n]+\\)#\\([0-9]+\\)\\))" 2 3 nil 2 1))
(add-to-list 'compilation-error-regexp-alist-alist
'(R3 "\\(?:^ +\\|: +\\)\\([^-+[:digit:]\n]:?[^:\n]*\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
(add-to-list 'compilation-error-regexp-alist-alist
'(R4 "\\([^-+ [:digit:]][^: \t\n]+\\):\\([0-9]+\\):\\([0-9]+\\):" 1 2 3 2 1))
(add-to-list 'compilation-error-regexp-alist-alist
'(R-recover " *[0-9]+: +\\([^:\n\t]+?\\)#\\([0-9]+:\\)" 1 2 nil 2 1))
(let ((r-ver '("R-1" "R-2" "R-3" "R-devel" "R-patched")))
(defvar ess-r-versions
(if (eq system-type 'darwin) (append r-ver '("R32" "R64")) r-ver)
"List of partial strings for versions of R to access within ESS.
Each string specifies the start of a filename. If a filename
beginning with one of these strings is found on `exec-path', a M-x
command for that version of R is made available. For example, if the
file \"R-1.8.1\" is found and this variable includes the string
\"R-1\", a function called `M-x R-1.8.1' will be available to run that
version of R.
If duplicate versions of the same program are found (which happens if
the same path is listed on `exec-path' more than once), they are
ignored by calling `ess-uniq-list'.
Set this variable to nil to disable searching for other versions of R.
If you set this variable, you need to restart Emacs (and set this variable
before ess-site is loaded) for it to take effect."))
(defvar ess-R-post-run-hook nil
"Functions run in process buffer after the initialization of R
process.")
(defun ess--R-load-ESSR ()
"Load/INSTALL/Update ESSR."
(let* ((ESSR-directory (expand-file-name "ESSR" ess-etc-directory))
(src-dir (expand-file-name "R" ESSR-directory)))
(if (not (or (and (boundp 'ess-remote) ess-remote)
(file-remote-p (ess-get-process-variable 'default-directory))))
(let ((cmd (format
"local({
source('%s/.load.R', local=TRUE) #define load.ESSR
load.ESSR('%s')})\n"
src-dir src-dir)))
(ess-write-to-dribble-buffer (format "load-ESSR cmd:\n%s\n" cmd))
(with-current-buffer (ess-command cmd)
(let ((msg (buffer-string)))
(when (> (length msg) 1)
(message (format "load ESSR: %s" msg))))))
(let* ((verfile (expand-file-name "VERSION" ESSR-directory))
(loadremote (expand-file-name "LOADREMOTE" ESSR-directory))
(version (if (file-exists-p verfile)
(with-temp-buffer
(insert-file-contents verfile)
(buffer-string))
(error "Cannot find ESSR source code")))
(r-load-code (with-temp-buffer
(insert-file-contents loadremote)
(buffer-string))))
(ess-write-to-dribble-buffer (format "version file: %s\nloadremote file: %s\n"
verfile loadremote))
(unless (ess-boolean-command (format r-load-code version) nil 0.1)
(let ((errmsg (with-current-buffer " *ess-command-output*" (buffer-string)))
(files (directory-files src-dir t "\\.R$")))
(ess-write-to-dribble-buffer (format "error loading ESSR.rda: \n%s\n" errmsg))
(message "Failed to download ESSR.rda (see *ESS* buffer). Injecting ESSR code from local machine")
(ess-command (format ".ess.ESSRversion <- '%s'\n" version))
(mapc #'ess--inject-code-from-file files)))))))
(defun R (&optional start-args)
"Call 'R', the 'GNU S' system from the R Foundation.
Optional prefix (C-u) allows to set command line arguments, such as
--vsize. This should be OS agnostic.
If you have certain command line arguments that should always be passed
to R, put them in the variable `inferior-R-args'."
(interactive "P")
(ess-write-to-dribble-buffer
(format
"\n(R): ess-dialect=%s, buf=%s, start-arg=%s\n current-prefix-arg=%s\n"
ess-dialect (current-buffer) start-args current-prefix-arg))
(let* ((r-always-arg
(if (or ess-microsoft-p (eq system-type 'cygwin))
"--ess "
(if (not ess-R-readline) "--no-readline ")))
(r-start-args
(concat r-always-arg
inferior-R-args " "
(if start-args
(read-string
(concat "Starting Args"
(if r-always-arg
(concat " [other than '" r-always-arg "']"))
" ? "))
nil)))
(cust-alist (copy-alist R-customize-alist))
(gdbp (string-match-p "gdb" r-start-args))
use-dialog-box)
(when gdbp
(setcdr (assoc 'inferior-ess-secondary-prompt cust-alist)
(format "\\(%s\\)\\|\\((gdb) \\)"
(cdr (assoc 'inferior-ess-secondary-prompt cust-alist)))))
(when (or ess-microsoft-p
(eq system-type 'cygwin))
(setq use-dialog-box nil)
(when ess-microsoft-p
(setq default-process-coding-system '(undecided-dos . undecided-dos))))
(inferior-ess r-start-args cust-alist gdbp)
(ess-process-put 'funargs-pre-cache ess-R--funargs-pre-cache)
(ess-process-put 'callbacks '(R-initialize-on-start))
(process-send-string (get-process ess-local-process-name) "\n")
(remove-hook 'completion-at-point-functions 'ess-filename-completion 'local)
(add-hook 'completion-at-point-functions 'ess-R-object-completion nil 'local)
(add-hook 'completion-at-point-functions 'ess-filename-completion nil 'local)
(setq comint-input-sender 'inferior-R-input-sender)
(ess-write-to-dribble-buffer
(format "(R): inferior-ess-language-start=%s\n"
inferior-ess-language-start))))
(defun R-initialize-on-start (&optional proc string)
"This function is run after the first R prompt.
Executed in process buffer."
(interactive)
(when ess-can-eval-in-background
(ess-async-command-delayed
"invisible(installed.packages())\n" nil (get-process ess-local-process-name)
(lambda (proc) (process-put proc 'packages-cached? t))))
(ess--R-load-ESSR)
(when inferior-ess-language-start
(ess-eval-linewise inferior-ess-language-start
nil nil nil 'wait-prompt))
(with-ess-process-buffer nil
(run-mode-hooks 'ess-R-post-run-hook)))
(defun R-mode (&optional proc-name)
"Major mode for editing R source. See `ess-mode' for more help."
(interactive "P")
(setq ess-customize-alist R-customize-alist)
(ess-mode R-customize-alist proc-name)
(add-hook 'comint-dynamic-complete-functions 'ess-complete-object-name t 'local)
(remove-hook 'completion-at-point-functions 'ess-filename-completion 'local)
(add-hook 'completion-at-point-functions 'ess-R-object-completion nil 'local)
(add-hook 'completion-at-point-functions 'ess-filename-completion nil 'local)
(if (fboundp 'ess-add-toolbar) (ess-add-toolbar))
(when (and ess-imenu-use-S (require 'ess-menu))
(setq imenu-generic-expression ess-imenu-generic-expression)
(imenu-add-to-menubar "Imenu-R"))
(set (make-local-variable 'beginning-of-defun-function)
(lambda (&optional arg)
(skip-chars-backward " \t\n")
(ess-beginning-of-function 'no-error)))
(set (make-local-variable 'end-of-defun-function)
'ess-end-of-function)
(ess-roxy-mode t)
(ad-activate 'mark-paragraph)
(ad-activate 'fill-paragraph)
(ad-activate 'move-beginning-of-line)
(ad-activate 'newline-and-indent)
(ad-activate 'ess-eval-line-and-step)
(if ess-roxy-hide-show-p
(ad-activate 'ess-indent-command))
(run-hooks 'R-mode-hook))
(fset 'r-mode 'R-mode)
(defun ess-R-arch-2-bit (arch)
"Translate R's architecture shortcuts/directory names to 'bits',
i.e., \"32\" or \"64\" (for now)."
(if (string= arch "i386") "32"
"64"))
(defun ess-rterm-arch-version (long-path &optional give-cons)
"Find an architecture-specific name for LONG-PATH, an absolute (long name) path
to R on Windows. Returns either Name, a string, or a (Name . Path) cons, such as
(\"R-2.12.1-64bit\" . \"C:/Program Files/R/R-2.12.1/bin/x64/Rterm.exe\")
\"R-x.y.z/bin/Rterm.exe\" will return \"R-x.y.z\", for R-2.11.x and older.
\"R-x.y.z/bin/i386/Rterm.exe\" will return \"R-x.y.z-32bit\", for R-2.12.x and newer.
\"R-x.y.z/bin/x64/Rterm.exe\" will return \"R-x.y.z-64bit\", for R-2.12.x and newer."
(let* ((dir (directory-file-name (file-name-directory long-path)))
(dir2 (directory-file-name (file-name-directory dir)))
(v-1up (file-name-nondirectory dir))
(v-2up (file-name-nondirectory dir2))
(v-3up (file-name-nondirectory
(directory-file-name (file-name-directory dir2))))
(val (if (string= v-2up "bin")
(concat v-3up "-" (ess-R-arch-2-bit v-1up) "bit")
v-2up)))
(if give-cons
(cons val long-path)
val)))
(defun ess-r-versions-create ()
"Generate the `M-x R-x.y.z' functions for starting other versions of R.
On MS Windows, this works using `ess-rterm-version-paths'; otherwise,
see `ess-r-versions' for strings that determine which functions are created.
The result is a list of the new R defuns, if any, that were created. The
defuns will normally be placed on the menubar and stored as
`ess-r-versions-created' upon ESS initialisation."
(if (not ess-r-versions)
nil
(let (versions
r-versions-created
(eval-buf (get-buffer-create "*ess-temp-r-evals*"))
(template
(concat
"(defun R-X.Y (&optional start-args)
\"Call the R version 'R-X.Y' using ESS.
This function was generated by `ess-r-versions-create'.\"
(interactive \"P\")
(let ((inferior-R-version \"R-X.Y\")
(inferior-R-program-name \""
(if ess-microsoft-p "Rterm" "R") "-X.Y\"))
(R start-args)))
"
) ))
(with-current-buffer eval-buf
(delete-region (point-min) (point-max))
(setq versions
(if ess-microsoft-p
(mapcar (lambda(v) (ess-rterm-arch-version v 'give-cons))
ess-rterm-version-paths)
(ess-uniq-list
(mapcar 'file-name-nondirectory
(apply 'nconc
(mapcar 'ess-find-exec-completions
ess-r-versions))))))
(setq r-versions-created
(if ess-microsoft-p
(mapcar 'car versions)
versions))
(ess-write-to-dribble-buffer
(format "(R): ess-r-versions-create making M-x defuns for \n %s\n"
(mapconcat 'identity r-versions-created "\n ")))
(while versions
(let* ((version (car versions))
(ver (if ess-microsoft-p (car version) version))
(beg (point)))
(setq versions (cdr versions))
(insert template)
(goto-char beg)
(while (search-forward "R-X.Y" nil t)
(replace-match ver t t))
(when ess-microsoft-p
(goto-char beg)
(while (search-forward "Rterm-X.Y" nil t)
(replace-match (w32-short-file-name (cdr version)) t t)))
(goto-char (point-max)))
)
(eval-buffer))
(unless (and (boundp 'ess-debugging) ess-debugging)
(kill-buffer eval-buf))
r-versions-created)))
(defvar ess-newest-R nil
"Stores the newest version of R that has been found. Used as a cache,
within ess-find-newest-R. Do not use this value directly, but
instead call the function \\[ess-find-newest-R].")
(defun ess-find-newest-R ()
"Find the newest version of R on the system. Once the value is found,
cache it in the variable `ess-newest-R' for future use as finding the
newest version of R can be potentially time-consuming."
(or ess-newest-R
(progn (message "Finding all versions of R on your system...")
nil)
(setq ess-newest-R
(ess-newest-r
(if ess-microsoft-p
ess-rterm-version-paths
(add-to-list 'ess-r-versions-created
inferior-R-program-name))))))
(defun ess-check-R-program-name ()
"Check if `inferior-R-program-name' points to an executable version of R.
If not, try to find the newest version of R elsewhere on the system, and
update `inferior-R-program-name' accordingly."
(unless (executable-find inferior-R-program-name)
(let ((newest (ess-find-newest-R)))
(if newest
(setq inferior-R-program-name newest)
(message "Sorry, no version of R could be found on your system.")))))
(defun R-newest (&optional start-args)
"Find the newest version of R available, and run it.
Subsequent calls to R-newest will run that version, rather than searching
again for the newest version. Providing an optional prefix arg (C-u) will
prompt for command line arguments."
(interactive "P")
(let ((rnewest (ess-find-newest-R)))
(if (not rnewest)
(error "No version of R could be found.")
(message (concat "Newest version of R is " rnewest))
(fset 'R-newest
(intern
(if ess-microsoft-p
(ess-rterm-arch-version rnewest)
rnewest)))
(R-newest start-args))))
(defun ess-r-version-date (rver)
"Return the date of the version of R named RVER.
The date is returned as a date string. If the version of R could
not be found from the output of the RVER program, \"-1\" is
returned."
(let ((date "-1")
(ver-string (shell-command-to-string
(concat (if ess-microsoft-p (w32-short-file-name rver) rver)
" --version"))))
(when (string-match
"R \\(version \\)?[1-9][^\n]+ (\\(2[0-9-]+\\)\\( r[0-9]+\\)?)"
ver-string)
(setq date (match-string 2 ver-string)))
(cons date rver)))
(defun ess-current-R-version ()
"Get the version of R currently running in the ESS buffer as a string"
(ess-make-buffer-current)
(car (ess-get-words-from-vector "as.character(.ess.Rversion)\n")))
(defun ess-current-R-at-least (version)
"Is the version of R (in the ESS buffer) at least (\">=\") VERSION ?
Examples: (ess-current-R-at-least '2.7.0)
or (ess-current-R-at-least \"2.5.1\")"
(ess-make-buffer-current)
(string= "TRUE"
(car (ess-get-words-from-vector
(format "as.character(.ess.Rversion >= \"%s\")\n" version)))))
(defvar ess-temp-newest nil)
(defun ess-newest-r (rvers)
"Check all the versions of RVERS to see which is the newest.
Return the name of the newest version of R."
(let ((rtimes (mapcar 'ess-r-version-date rvers)))
(setq ess-temp-newest rtimes)
(ess-find-newest-date rtimes)))
(defun ess-find-newest-date (rvers)
"Find the newest version of R given in the a-list RVERS.
Each element of RVERS is a dotted pair (date . R-version), where
date is given as e.g.\"2007-11-30\" so that we can compare dates
as strings. If a date is listed as \"-1\", that version of R
could not be found.
If the value returned is nil, no valid newest version of R could be found."
(let (new-r this-r
(new-time "0"))
(while rvers
(setq this-r (car rvers)
rvers (cdr rvers))
(when (string< new-time (car this-r))
(setq new-time (car this-r)
new-r (cdr this-r))))
new-r))
(defun ess-find-rterm (&optional ess-R-root-dir bin-Rterm-exe)
"Find the full path of all occurences of Rterm.exe under the ESS-R-ROOT-DIR.
If ESS-R-ROOT-DIR is nil, construct it by looking for an occurence of Rterm.exe
in the exec-path. If there are no occurences of Rterm.exe in the exec-path,
then use `ess-program-files' (which evaluates to something like \"c:/progra~1/R/\"
in English locales) which is the default location for the R distribution.
If BIN-RTERM-EXE is nil, then use \"bin/Rterm.exe\"."
(if (not ess-R-root-dir)
(let ((Rpath (executable-find "Rterm")))
(setq ess-R-root-dir
(expand-file-name
(if Rpath
(concat (file-name-directory Rpath) "../../")
(concat ess-program-files "/R/"))))
(ess-write-to-dribble-buffer
(format "(ess-find-rterm): ess-R-root-dir = '%s'\n" ess-R-root-dir))
))
(if (not bin-Rterm-exe) (setq bin-Rterm-exe "bin/Rterm.exe"))
(when (file-directory-p ess-R-root-dir)
(setq ess-R-root-dir
(ess-replace-regexp-in-string "[\\]" "/" ess-R-root-dir))
(let ((R-ver
(ess-drop-non-directories
(ess-flatten-list
(mapcar (lambda (r-prefix)
(file-name-all-completions r-prefix ess-R-root-dir))
(append '("rw") ess-r-versions))))))
(mapcar (lambda (dir)
(let ((R-path
(concat ess-R-root-dir
(ess-replace-regexp-in-string "[\\]" "/" dir)
bin-Rterm-exe)))
(if (file-exists-p R-path) R-path)))
R-ver))))
(defun ess-R-eldoc-function ()
"Return the doc string, or nil.
If an ESS process is not associated with the buffer, do not try
to look up any doc strings."
(interactive)
(let ((proc (ess-get-next-available-process)))
(when proc
(let ((funname (or (and ess-eldoc-show-on-symbol
(thing-at-point 'symbol))
(car (ess--funname.start)))))
(when funname
(let* ((args (ess-function-arguments funname proc))
(bargs (cadr args))
(doc (mapconcat (lambda (el)
(if (equal (car el) "...")
"..."
(concat (car el) "=" (cdr el))))
bargs ", "))
(margs (nth 2 args))
(W (- (window-width (minibuffer-window)) (+ 4 (length funname))))
doc1)
(when doc
(setq doc (ess-eldoc-docstring-format funname doc))
(when (and margs (< (length doc1) W))
(setq doc1 (concat doc (propertize " || " 'face font-lock-function-name-face)))
(while (and margs (< (length doc1) W))
(let ((head (pop margs)))
(unless (assoc head bargs)
(setq doc doc1
doc1 (concat doc1 head "=, ")))))
(when (equal (substring doc -2) ", ")
(setq doc (substring doc 0 -2)))
(when (and margs (< (length doc) W))
(setq doc (concat doc " {--}"))))
doc)))))))
(defun ess-eldoc-docstring-format (funname doc)
(save-match-data
(let* (
(truncate (or (not (eq t eldoc-echo-area-use-multiline-p))
(eq ess-eldoc-abbreviation-style 'aggressive)))
(W (1- (- (window-width (minibuffer-window))
(+ 2 (length funname)))))
newdoc
)
(setq doc
(if (or (<= (length doc) W)
(null ess-eldoc-abbreviation-style)
(eq 'none ess-eldoc-abbreviation-style))
doc
(setq doc (replace-regexp-in-string "TRUE" "T" doc))
(setq doc (replace-regexp-in-string "FALSE" "F" doc))
(if (or (<= (length doc) W)
(eq 'mild ess-eldoc-abbreviation-style))
doc
(setq doc (replace-regexp-in-string
"([^)]\\{8\\}\\([^)]\\{4,\\}\\))"
"{.}" doc nil nil 1))
(if (<= (length doc) W)
doc
(setq doc (replace-regexp-in-string
" +[^ \t=,\"\]+=[^ \t]\\{10\\}\\([^ \t]\\{4,\\}\\)\\(,\\|\\'\\)"
"{.}," doc nil nil 1))
(if (<= (length doc) W)
doc
(setq doc (replace-regexp-in-string
" +[^ \t=,\"]+=\\([^ \t]\\{10,\\}\\)\\(,\\|\\'\\)"
"{.}," doc nil nil 1))
(if (or (<= (length doc) W)
(eq 'normal ess-eldoc-abbreviation-style))
doc
(setq doc (replace-regexp-in-string
" *[^ \t=,\"\\]* = \\([^ \t]\\{4,\\}\\)\\(,\\|\\'\\)"
"{.}," doc nil nil 1))
(if (<= (length doc) W)
doc
(setq doc (replace-regexp-in-string
"\\(=[^FT0-9].+?\\)\\(, [^ =,\"\\]+=\\|\\'\\)"
"" doc nil nil 1))
(setq doc (replace-regexp-in-string
"\\(=[^FT0-9].+?\\)\\(, [^ =,\"\\]+,\\|\\'\\)"
"" doc nil nil 1))
(if (or (<= (length doc) W)
(eq 'strong ess-eldoc-abbreviation-style))
doc
(concat (substring doc 0 (- W 4)) "{--}")))))))))
(when (and truncate
(> (length doc) W))
(setq doc (concat (substring doc 0 (- W 4)) "{--}")))
(format "%s: %s" (propertize funname 'face 'font-lock-function-name-face) doc))))
(defvar ess-R--funargs-pre-cache
'(("plot"
(("graphics")
(("x" . "") ("y" . "NULL") ("type" . "p") ("xlim" . "NULL") ("ylim" . "NULL") ("log" . "") ("main" . "NULL") ("sub" . "NULL") ("xlab" . "NULL") ("ylab" . "NULL")
("ann" . "par(\"ann\")") ("axes" . "TRUE") ("frame.plot" . "axes") ("panel.first" . "NULL") ("panel.last" . "NULL") ("asp" . "NA") ("..." . ""))
("x" "y" "..." "ci" "type" "xlab" "ylab" "ylim" "main" "ci.col" "ci.type" "max.mfrow" "ask" "mar" "oma" "mgp" "xpd" "cex.main" "verbose" "scale" "xlim" "log" "sub" "ann" "axes" "frame.plot" "panel.first" "panel.last" "asp" "center" "edge.root" "nodePar" "edgePar" "leaflab" "dLeaf" "xaxt" "yaxt" "horiz" "zero.line" "verticals" "col.01line" "pch" "legend.text" "formula" "data" "subset" "to" "from" "newpage" "vp" "labels" "hang" "freq" "density" "angle" "col" "border" "lty" "add" "predicted.values" "intervals" "separator" "col.predicted" "col.intervals" "col.separator" "lty.predicted" "lty.intervals" "lty.separator" "plot.type" "main2" "par.fit" "grid" "panel" "cex" "dimen" "abbrev" "which" "caption" "sub.caption" "id.n" "labels.id" "cex.id" "qqline" "cook.levels" "add.smooth" "label.pos" "cex.caption" "rows" "levels" "conf" "absVal" "ci.lty" "xval" "do.points" "col.points" "cex.points" "col.hor" "col.vert" "lwd" "set.pars" "range.bars" "col.range" "xy.labels" "xy.lines" "nc" "yax.flip" "mar.multi" "oma.multi")))
("print"
(("base")
(("x" . "") ("digits" . "NULL") ("quote" . "TRUE") ("na.print" . "NULL") ("print.gap" . "NULL") ("right" . "FALSE") ("max" . "NULL") ("useSource" . "TRUE") ("..." . ""))
("x" "..." "digits" "signif.stars" "intercept" "tol" "se" "sort" "verbose" "indent" "style" ".bibstyle" "prefix" "vsep" "minlevel" "quote" "right" "row.names" "max" "na.print" "print.gap" "useSource" "diag" "upper" "justify" "title" "max.levels" "width" "steps" "showEnv" "newpage" "vp" "cutoff" "max.level" "give.attr" "units" "abbrCollate" "print.x" "deparse" "locale" "symbolic.cor" "loadings" "zero.print" "calendar")))
)
"Alist of cached arguments for very time consuming functions.")
(defun ess-R-object-completion ()
"Return completions at point in a format required by `completion-at-point-functions'. "
(if (ess-make-buffer-current)
(let* ((funstart (cdr (ess--funname.start)))
(completions (ess-R-get-rcompletions funstart))
(token (pop completions)))
(when completions
(list (- (point) (length token)) (point) completions)))
(when (string-match "complete" (symbol-name last-command))
(message "No ESS process associated with current buffer")
nil)
))
(defun ess-complete-object-name ()
"Perform completion on `ess-language' object preceding point.
Uses \\[ess-R-complete-object-name] when `ess-use-R-completion' is non-nil,
or \\[ess-internal-complete-object-name] otherwise."
(interactive)
(if (ess-make-buffer-current)
(if ess-use-R-completion
(ess-R-complete-object-name)
(ess-internal-complete-object-name))
(when (string-match "complete" (symbol-name last-command))
(message "No ESS process associated with current buffer")
nil)
))
(defun ess-complete-object-name-deprecated ()
"Gives a deprecated message "
(interactive)
(ess-complete-object-name)
(message "C-c TAB is deprecated, completions has been moved to [M-TAB] (aka C-M-i)")
(sit-for 2 t)
)
(defun ess-internal-complete-object-name ()
"Perform completion on `ess-language' object preceding point.
The object is compared against those objects known by
`ess-get-object-list' and any additional characters up to ambiguity are
inserted. Completion only works on globally-known objects (including
elements of attached data frames), and thus is most suitable for
interactive command-line entry, and not so much for function editing
since local objects (e.g. argument names) aren't known.
Use \\[ess-resynch] to re-read the names of the attached directories.
This is done automatically (and transparently) if a directory is
modified (S only!), so the most up-to-date list of object names is always
available. However attached dataframes are *not* updated, so this
command may be necessary if you modify an attached dataframe."
(interactive)
(ess-make-buffer-current)
(if (memq (char-syntax (preceding-char)) '(?w ?_))
(let* ((comint-completion-addsuffix nil)
(end (point))
(buffer-syntax (syntax-table))
(beg (unwind-protect
(save-excursion
(set-syntax-table ess-mode-syntax-table)
(backward-sexp 1)
(point))
(set-syntax-table buffer-syntax)))
(full-prefix (buffer-substring beg end))
(pattern full-prefix)
(listname (if (string-match "\\(.+\\)\\$\\(\\(\\sw\\|\\s_\\)*\\)$"
full-prefix)
(progn
(setq pattern
(if (not (match-beginning 2)) ""
(substring full-prefix
(match-beginning 2)
(match-end 2))))
(substring full-prefix (match-beginning 1)
(match-end 1)))))
(classname (if (string-match "\\(.+\\)@\\(\\(\\sw\\|\\s_\\)*\\)$"
full-prefix)
(progn
(setq pattern
(if (not (match-beginning 2)) ""
(substring full-prefix
(match-beginning 2)
(match-end 2))))
(ess-write-to-dribble-buffer
(format "(ess-C-O-Name : slots..) : patt=%s"
pattern))
(substring full-prefix (match-beginning 1)
(match-end 1)))))
(components (if listname
(ess-object-names listname)
(if classname
(ess-slot-names classname)
(ess-get-object-list ess-current-process-name)))))
(or (comint-dynamic-simple-complete pattern components) 'none))))
(defun ess-R-get-rcompletions (&optional start end)
"Call R internal completion utilities (rcomp) for possible completions.
Needs version of R>2.7.0
Optional START and END delimit the entity to complete, default to bol and point.
First element of a returned list is the completion token.
"
(let* ((start (or start
(save-excursion (comint-bol nil) (point))))
(end (or end (point)))
(comm (format ".ess_get_completions(\"%s\", %d)\n"
(ess-quote-special-chars (buffer-substring start end))
(- end start))))
(ess-get-words-from-vector comm)))
(defun ess-R-complete-object-name ()
"Completion in R via R's completion utilities (formerly 'rcompgen').
To be used instead of ESS' completion engine for R versions >= 2.7.0."
(interactive)
(let ((possible-completions (ess-R-get-rcompletions))
token-string)
(when possible-completions
(setq token-string (pop possible-completions))
(or (comint-dynamic-simple-complete token-string
possible-completions)
'none))))
(defvar ac-source-R
'((prefix . ess-ac-start)
(candidates . ess-ac-candidates)
(document . ess-ac-help)
)
"Combined ad-completion source for R function arguments and R objects")
(defun ess-ac-start ()
(when (and ess-local-process-name
(get-process ess-local-process-name))
(or (ess-ac-start-args)
(ess-symbol-start))))
(defun ess-ac-candidates ()
"OBJECTS + ARGS"
(let ((args (ess-ac-args)))
(if (and ac-auto-start
(< (length ac-prefix) ac-auto-start))
args
(if args
(append args (ess-ac-objects t))
(ess-ac-objects)))))
(defun ess-ac-help (sym)
(if (string-match-p "= *\\'" sym)
(ess-ac-help-arg sym)
(ess-ac-help-object sym)))
(defvar ac-source-R-objects
'((prefix . ess-symbol-start)
(candidates . ess-ac-objects)
(document . ess-ac-help-object))
"Auto-completion source for R objects")
(defun ess-ac-objects (&optional no-kill)
"Get all cached objects"
(let ((aprf ac-prefix))
(when aprf
(unless no-kill
(kill-local-variable 'ac-use-comphist))
(if (string-match-p "[]:$@[]" aprf)
(cdr (ess-R-get-rcompletions ac-point))
(with-ess-process-buffer 'no-error
(ess-when-new-input last-objlist-update
(if (and ess-sl-modtime-alist
(not (process-get *proc* 'sp-for-ac-changed?)))
(ess-extract-onames-from-alist ess-sl-modtime-alist 1 'force))
(ess-get-modtime-list)
(process-put *proc* 'sp-for-ac-changed? nil))
(apply 'append (mapcar 'cddr ess-sl-modtime-alist)))))))
(defun ess-ac-help-object (sym)
"Help string for ac."
(let ((buf (get-buffer-create " *ess-command-output*")))
(when (string-match ":+\\(.*\\)" sym)
(setq sym (match-string 1 sym)))
(ess-with-current-buffer buf
(ess--flush-help-into-current-buffer sym nil t))
(with-current-buffer buf
(ess-help-underline)
(goto-char (point-min))
(buffer-string))))
(defvar ac-source-R-args
'((prefix . ess-ac-start-args)
(candidates . ess-ac-args)
(document . ess-ac-help-arg)
)
"Auto-completion source for R function arguments")
(defun ess-ac-start-args ()
"Get initial position for args completion"
(when (and ess-local-process-name
(not (eq (get-text-property (point) 'face) 'font-lock-string-face)))
(when (ess--funname.start)
(if (looking-back "[(,]+[ \t\n]*")
(point)
(ess-symbol-start)))))
(defun ess-ac-args ()
"Get the args of the function when inside parentheses."
(when ess--funname.start
(let ((args (nth 2 (ess-function-arguments (car ess--funname.start))))
(len (length ac-prefix)))
(if args
(set (make-local-variable 'ac-use-comphist) nil)
(kill-local-variable 'ac-use-comphist))
(delete "..." args)
(mapcar (lambda (a) (concat a ess-ac-R-argument-suffix))
args))))
(defun ess-ac-help-arg (sym)
"Help string for ac."
(setq sym (replace-regexp-in-string " *= *\\'" "" sym))
(let ((fun (car ess--funname.start)))
(with-current-buffer (ess-command (format ess--ac-help-arg-command sym fun))
(goto-char (point-min))
(forward-line)
(buffer-substring-no-properties (point) (point-max)))))
(defvar ess--ac-help-arg-command
"
getArgHelp <- function(arg, func=NULL){
olderr <- getOption('error')
options(error=NULL)
on.exit(options(error=olderr))
fguess <-
if(is.null(func)) get('fguess', envir=utils:::.CompletionEnv)
else func
findArgHelp <- function(fun, arg){
file <- help(fun, try.all.packages=FALSE)[[1]]
hlp <- utils:::.getHelpFile(file)
id <- grep('arguments', tools:::RdTags(hlp), fixed=TRUE)
if(length(id)){
arg_section <- hlp[[id[[1L]]]]
items <- grep('item', tools:::RdTags(arg_section), fixed=TRUE)
## cat('items:', items, fill=TRUE)
if(length(items)){
arg_section <- arg_section[items]
args <- unlist(lapply(arg_section,
function(el) paste(unlist(el[[1]][[1]], TRUE, FALSE), collapse='')))
fits <- grep(arg, args, fixed=TRUE)
## cat('args', args, 'fits', fill=TRUE)
if(length(fits))
paste(unlist(arg_section[[fits[1L]]][[2]], TRUE, FALSE), collapse='')
}
}
}
funcs <- c(fguess, tryCatch(methods(fguess),
warning=function(w) {NULL},
error=function(e) {NULL}))
if(length(funcs) > 1 && length(pos <- grep('default', funcs))){
funcs <- c(funcs[[pos[[1L]]]], funcs[-pos[[1L]]])
}
i <- 1L; found <- FALSE
out <- 'No help found'
while(i <= length(funcs) && is.null(out <-
tryCatch(findArgHelp(funcs[[i]], arg),
warning=function(w) {NULL},
error=function(e) {NULL})
))
i <- i + 1L
cat(' \n\n', as.character(out), '\n\n')
}; getArgHelp('%s','%s')
")
(defun Rnw-mode ()
"Major mode for editing Sweave(R) source.
See `ess-noweb-mode' and `R-mode' for more help."
(interactive)
(require 'ess-noweb)
(setq ess--make-local-vars-permenent t)
(ess-noweb-mode 1)
(ess-noweb-set-doc-mode 'latex-mode)
(ess-noweb-set-code-mode 'R-mode)
(setq ess--local-handy-commands
(append '(("weave" . ess-swv-weave)
("tangle" . ess-swv-tangle))
ess-handy-commands)
ess-dialect "R"
ess-language "S")
(put 'ess--local-handy-commands 'permanent-local t)
(run-hooks 'Rnw-mode-hook))
(fset 'Snw-mode 'Rnw-mode)
(autoload 'ess-transcript-mode "ess-trns"
"Major mode for editing S transcript files." t)
(defun R-transcript-mode ()
"Does the right thing."
(interactive)
(ess-transcript-mode R-customize-alist))
(fset 'r-transcript-mode 'R-transcript-mode)
(defun R-fix-T-F (&optional from quietly)
"Fix T/F into TRUE and FALSE *cautiously*, i.e. not in comments and strings;
starting from the current position (point)."
(interactive "d\nP")
(save-excursion
(goto-char from)
(ess-rep-regexp "\\(\\([][=,()]\\|<-\\) *\\)T\\>" "\\1TRUE"
'fixcase nil (not quietly))
(goto-char from)
(ess-rep-regexp "\\(\\([][=,()]\\|<-\\) *\\)F\\>" "\\1FALSE"
'fixcase nil (not quietly))))
(defun R-site-search (string)
"Search the R archives for STRING, using default criteria. If
called with a prefix, options are available for
1) matches per page,
2) sections of the archives to search (separated by value of `crm-default-separator'),
3) for displaying results in long or short formats, and
4) for sorting by any given field.
Completion is available for supplying options."
(interactive "sSearch string: ")
(let ((site "http://search.r-project.org/cgi-bin/namazu.cgi?query=")
(okstring (replace-regexp-in-string " +" "+" string)))
(if current-prefix-arg
(let ((mpp (concat
"&max="
(completing-read
"Matches per page: "
'(("20" 1) ("30" 2) ("40" 3) ("50" 4) ("100" 5)))))
(format (concat
"&result="
(completing-read
"Format: " '("normal" "short")
nil t "normal" nil "normal")))
(sortby (concat
"&sort="
(completing-read
"Sort by: "
'(("score" 1) ("date:late" 2) ("date:early" 3)
("field:subject:ascending" 4)
("field:subject:decending" 5)
("field:from:ascending" 6) ("field:from:decending" 7)
("field:size:ascending" 8) ("field:size:decending" 9))
nil t "score" nil "score")))
(restrict (concat
"&idxname="
(mapconcat
'identity
(completing-read-multiple
"Limit search to: "
'(("Rhelp02a" 1) ("functions" 2) ("docs" 3)
("Rhelp01" 4))
nil t "Rhelp02a,functions,docs" nil
"Rhelp02a,functions,docs") "&idxname="))))
(browse-url (concat site okstring mpp format sortby restrict)))
(browse-url (concat site okstring "&max=20&result=normal&sort=score"
"&idxname=Rhelp02a&idxname=functions&idxname=docs")))))
(defvar ess--packages-cache nil
"Cache var to store package names. Used by
`ess-install.packages'.")
(defun ess-R-install.packages (&optional update pack)
"Prompt and install R package. With argument, update cached packages list."
(interactive "P")
(when (equal "@CRAN@" (car (ess-get-words-from-vector "getOption('repos')[['CRAN']]\n")))
(ess-setCRANMiror)
(ess-wait-for-process (get-process ess-current-process-name))
(unless pack (setq update t)))
(when (or update
(not ess--packages-cache))
(message "Fetching R packages ... ")
(setq ess--packages-cache
(ess-get-words-from-vector "print(rownames(available.packages()), max=1e6)\n")))
(let* ((ess-eval-visibly-p t)
(pack (or pack
(ess-completing-read "Package to install" ess--packages-cache))))
(process-send-string (get-process ess-current-process-name)
(format "install.packages('%s')\n" pack))
(display-buffer (buffer-name (process-buffer (get-process ess-current-process-name))))
))
(define-obsolete-function-alias 'ess-install.packages 'ess-R-install.packages "ESS[12.09-1]")
(defun ess-install-library ()
"Install library/package for current dialect.
Currently works only for R."
(interactive)
(if (not (string-match "^R" ess-dialect))
(message "Sorry, not available for %s" ess-dialect)
(ess-R-install.packages)))
(defun ess-setRepositories ()
"Call setRepositories()"
(interactive)
(if (not (string-match "^R" ess-dialect))
(message "Sorry, not available for %s" ess-dialect)
(ess-eval-linewise "setRepositories(FALSE)\n")
))
(defun ess-setCRANMiror ()
"Set cran mirror"
(interactive)
(let* ((M1 (ess-get-words-from-vector "local({out <- getCRANmirrors(local.only=TRUE); print(paste(out$Name,'[',out$URL,']', sep=''))})\n"))
(M2 (mapcar (lambda (el)
(string-match "\\(.*\\)\\[\\(.*\\)\\]$" el)
(propertize (match-string 1 el) 'URL (match-string 2 el)))
M1))
(opt (ess-completing-read "Choose CRAN mirror" M2 nil t)))
(when opt
(setq opt (get-text-property 0 'URL opt))
(ess-command
(format "local({r <- getOption('repos'); r['CRAN'] <- '%s';options(repos=r)})\n" opt))
(message "New CHRAN mirror: %s" (car (ess-get-words-from-vector "getOption('repos')[['CRAN']]\n")))
)))
(defun ess-R-sos (cmd)
"Interface to findFn in the library sos."
(interactive "sfindFn: ")
(unless (equal "TRUE" (car (ess-get-words-from-vector "as.character(suppressPackageStartupMessages(require(sos)))\n")))
(if (y-or-n-p "Library 'sos' is not installed. Install? ")
(progn (ess-eval-linewise "install.packages('sos')\n")
(ess-eval-linewise "library(sos)\n"))
(signal 'quit nil)))
(message nil)
(ess-eval-linewise (format "findFn(\"%s\", maxPages=10)" cmd))
)
(define-obsolete-function-alias 'ess-sos 'ess-R-sos "ESS[12.09-1]")
(defun ess-load-library ()
"Prompt and load dialect specific library/package/module.
Note that add-ons in R are called 'packages' and the name of this
function has nothing to do with R package mechanism, but it
rather serves a generic, dialect independent purpose. It is also
similar to `load-library' emacs function."
(interactive)
(if (not (string-match "^R" ess-dialect))
(message "Sorry, not available for %s" ess-dialect)
(let ((ess-eval-visibly-p t)
(packs (ess-get-words-from-vector "print(.packages(T), max=1e6)\n"))
pack)
(setq pack (ess-completing-read "Load" packs))
(ess-eval-linewise (format "library('%s')\n" pack))
(ess--mark-search-list-as-changed)
(display-buffer (buffer-name (process-buffer (get-process ess-current-process-name))))
)))
(define-obsolete-function-alias 'ess-library 'ess-load-library "ESS[12.09-1]")
(provide 'ess-r-d)