~ubuntu-branches/ubuntu/maverick/ess/maverick

« back to all changes in this revision

Viewing changes to lisp/essa-r.el

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2010-03-03 06:25:04 UTC
  • mfrom: (1.2.13 upstream) (3.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100303062504-rtei3p11s1gmcj4r
Tags: 5.8-1
New upstream version released this morning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;;; essa-r.el -- Possible local customizations for R with ESS.
2
 
 
3
 
;; Copyright (C) 1997--2005 A.J. Rossini, Rich M. Heiberger, Martin
4
 
;;      Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
 
 
6
 
;; Original Author: A.J. Rossini <blindglobe@gmail.com>
7
 
;; Created: 17 November 1999
8
 
;; Maintainers: ESS-core <ESS-core@stat.math.ethz.ch>
9
 
 
10
 
;; Keywords: editing and process modes.
11
 
 
12
 
;; This file is part of ESS
13
 
 
14
 
;; This file is free software; you can redistribute it and/or modify
15
 
;; it under the terms of the GNU General Public License as published by
16
 
;; the Free Software Foundation; either version 2, or (at your option)
17
 
;; any later version.
18
 
;;
19
 
;; This file is distributed in the hope that it will be useful,
20
 
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
;; GNU General Public License for more details.
23
 
;;
24
 
;; You should have received a copy of the GNU General Public License
25
 
;; along with GNU Emacs; see the file COPYING.  If not, write to
26
 
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27
 
;;
28
 
;; In short: you may use this code any way you like, as long as you
29
 
;; don't charge money for it, remove this notice, or hold anyone liable
30
 
;; for its results.
31
 
 
32
 
;;; Code:
33
 
 
34
 
;;; The purpose of this file is to demonstrate some of the extras that
35
 
;;; have been constructed for the ESS R mode; if they prove
36
 
;;; interesting, then they might be migrated to essd-r, the primary
37
 
;;; ESS R mode tools.
38
 
 
39
 
 
40
 
 
41
 
 
42
 
;; you can invoke ESS/R from emacs by typing
43
 
;;      C-u M-x essr
44
 
;; with vsize set to (for example) 40M, and nsize set to 600000.
45
 
(defalias 'essr
46
 
  (read-kbd-macro
47
 
     "C-u M-x R RET - - vsize SPC 40M SPC - - nsize SPC 600000 2*RET"))
48
 
;; "SPC" must be "=" in future versions of R (works from 0.99 on)
49
 
 
50
 
(defun ess-r-do-region (start end &optional message)
51
 
  "Send the current region to R via AppleScript."
52
 
  (interactive "r\nP")
53
 
  (message "Starting evaluation...")
54
 
  (do-applescript (concat
55
 
    "try\n"
56
 
        "tell application \"R\"\n"
57
 
                "activate\n"
58
 
                "with timeout of 0 seconds\n"
59
 
                        "cmd \"" (buffer-substring start end)
60
 
                        "\"\n"
61
 
                "end timeout\n"
62
 
        "end tell\n"
63
 
    "end try\n"))
64
 
  (message "Finished evaluation"))
65
 
 
66
 
(defun ess-r-do-line ()
67
 
  "Send the current line to R via AppleScript."
68
 
  (interactive) ;; "r\nP")
69
 
  (message "Starting evaluation...")
70
 
  (save-excursion
71
 
  (let ((end (point)))
72
 
  (move-to-column 0)
73
 
  (do-applescript (concat
74
 
    "try\n"
75
 
        "tell application \"R\"\n"
76
 
                "activate\n"
77
 
                "with timeout of 0 seconds\n"
78
 
                        "cmd \"" (buffer-substring (point) end)
79
 
                        "\"\n"
80
 
                "end timeout\n"
81
 
        "end tell\n"
82
 
    "end try\n"))))
83
 
  (message "Finished evaluation"))
84
 
 
85
 
(defun ess-r-var (beg end)
86
 
  "Load the current region of numbers into an R variable.  Prompts for
87
 
a variable name.  If none is given, it uses a default variable name,
88
 
e.  BEG and END denote the region in the current buffer to be sent."
89
 
  (interactive "r")
90
 
  (save-window-excursion
91
 
    (let ((tmp-file (make-temp-file "ess-r-var"))
92
 
          cmd
93
 
          var)
94
 
      (write-region beg end tmp-file)
95
 
 
96
 
      ;; Decide on the variable name to use in R; could use completion.
97
 
      (setq var (read-string "R Variable name (default e): "))
98
 
      (if (equal var "")
99
 
          (setq var "e"))
100
 
 
101
 
      ;; Command to send to the R process.  Get R to delete the file
102
 
      ;; rather than Emacs in case it takes R a long time to run the
103
 
      ;; scan command.
104
 
      (setq cmd (concat var " <- scan(\""  tmp-file "\"); "
105
 
                        "unlink(\"" tmp-file "\")" ))
106
 
 
107
 
      ;; Put the output from the scan command into the process buffer so
108
 
      ;; the user has a record of it.
109
 
      (ess-execute cmd 'buffer))))
110
 
 
111
 
 
112
 
;;; Peter Dalgaard's code.
113
 
;;; This needs to be cleaned and validated!
114
 
 
115
 
(defun pd::set-up-demo ()
116
 
 
117
 
  ;; (if (not xemacs) (set-default-font "*courier-bold-r*--14**"))
118
 
  (R)
119
 
  (split-window-vertically 6)
120
 
  (find-file "demos.R")
121
 
 
122
 
  ;; Don't need to run this as a function -- ought to be fine if set
123
 
  ;; just once.
124
 
 
125
 
  (defun ajr::scroll-to-end::peterD (emacs)
126
 
    "Goal: map prompt to bottom of the screen after every command.
127
 
Alternatively, use the scroll-in-place package, not sure where that
128
 
is)."
129
 
    (interactive)
130
 
    (other-buffer 1)
131
 
    (if (= emacs "emacs")
132
 
        (setq scroll-up-aggressively t)
133
 
      (setq scroll-conservatively -4)) ;; <- change this
134
 
    (other-buffer -1))
135
 
 
136
 
  (defun show-max-other-window ()
137
 
    (interactive)
138
 
    (other-window 1)
139
 
    (comint-show-maximum-output)
140
 
    (other-window -1))
141
 
 
142
 
  ;; call this once
143
 
  ;; (ajr::scroll-to-end::peterD "xemacs")
144
 
  ;; (ajr::scroll-to-end::peterD "emacs")
145
 
 
146
 
  (global-set-key [f11] 'show-max-other-window)
147
 
  (global-set-key [f12] 'ess-eval-line-and-step))
148
 
 
149
 
 
150
 
 ; Provide package
151
 
 
152
 
(provide 'essa-r)
153
 
 
154
 
 ; Local variables section
155
 
 
156
 
;;; This file is automatically placed in Outline minor mode.
157
 
;;; The file is structured as follows:
158
 
;;; Chapters:     ^L ;
159
 
;;; Sections:    ;;*;;
160
 
;;; Subsections: ;;;*;;;
161
 
;;; Components:  defuns, defvars, defconsts
162
 
;;;              Random code beginning with a ;;;;* comment
163
 
 
164
 
;;; Local variables:
165
 
;;; mode: emacs-lisp
166
 
;;; outline-minor-mode: nil
167
 
;;; mode: outline-minor
168
 
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
169
 
;;; End:
170
 
 
171
 
;;; ess-site.el ends here