Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
;;; ess-r-a.el -- Possible local customizations for R with ESS.
2
3
;; Copyright (C) 1997--2005 A.J. Rossini, Richard M. Heiberger, Martin
4
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
5
6
;; Author: A.J. Rossini <[email protected]>
7
;; Created: 17 November 1999
8
;; Maintainer: ESS-core <[email protected]>
9
10
;; Keywords: languages
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
;; A copy of the GNU General Public License is available at
25
;; http://www.r-project.org/Licenses/
26
27
;;; Commentary:
28
29
;; The purpose of this file is to demonstrate some of the extras that
30
;; have been constructed for the ESS R mode; if they prove
31
;; interesting, then they might be migrated to ess-r-d, the primary
32
;; ESS R mode tools.
33
34
;;; Code:
35
36
;; you can invoke ESS/R from emacs by typing
37
;; C-u M-x essr
38
;; with vsize set to (for example) 40M, and nsize set to 600000.
39
(defalias 'essr
40
(read-kbd-macro
41
"C-u M-x R RET - - vsize = 40M SPC - - nsize = 600000 2*RET"))
42
43
(defun ess-r-do-region (start end &optional message)
44
"Send the current region to R via AppleScript."
45
(interactive "r\nP")
46
(message "Starting evaluation...")
47
(do-applescript (concat
48
"try\n"
49
"tell application \"R\"\n"
50
"activate\n"
51
"with timeout of 0 seconds\n"
52
"cmd \"" (buffer-substring start end)
53
"\"\n"
54
"end timeout\n"
55
"end tell\n"
56
"end try\n"))
57
(message "Finished evaluation"))
58
59
(defun ess-r-do-line ()
60
"Send the current line to R via AppleScript."
61
(interactive) ;; "r\nP")
62
(message "Starting evaluation...")
63
(save-excursion
64
(let ((end (point)))
65
(move-to-column 0)
66
(do-applescript (concat
67
"try\n"
68
"tell application \"R\"\n"
69
"activate\n"
70
"with timeout of 0 seconds\n"
71
"cmd \"" (buffer-substring (point) end)
72
"\"\n"
73
"end timeout\n"
74
"end tell\n"
75
"end try\n"))))
76
(message "Finished evaluation"))
77
78
(defun ess-r-var (beg end)
79
"Load the current region of numbers into an R variable. Prompts for
80
a variable name. If none is given, it uses a default variable name,
81
e. BEG and END denote the region in the current buffer to be sent."
82
(interactive "r")
83
(save-window-excursion
84
(let ((tmp-file (make-temp-file "ess-r-var"))
85
cmd
86
var)
87
(write-region beg end tmp-file)
88
89
;; Decide on the variable name to use in R; could use completion.
90
(setq var (read-string "R Variable name (default e): "))
91
(if (equal var "")
92
(setq var "e"))
93
94
;; Command to send to the R process. Get R to delete the file
95
;; rather than Emacs in case it takes R a long time to run the
96
;; scan command.
97
(setq cmd (concat var " <- scan(\"" tmp-file "\"); "
98
"unlink(\"" tmp-file "\")" ))
99
100
;; Put the output from the scan command into the process buffer so
101
;; the user has a record of it.
102
(ess-execute cmd 'buffer))))
103
104
105
;;; Peter Dalgaard's code.
106
;;; This needs to be cleaned and validated!
107
108
(defun pd::set-up-demo ()
109
110
;; (if (not xemacs) (set-default-font "*courier-bold-r*--14**"))
111
(R)
112
(split-window-vertically 6)
113
(find-file "demos.R")
114
115
;; Don't need to run this as a function -- ought to be fine if set
116
;; just once.
117
118
(defun ajr::scroll-to-end::peterD (emacs)
119
"Goal: map prompt to bottom of the screen after every command.
120
Alternatively, use the scroll-in-place package, not sure where that
121
is)."
122
(interactive)
123
(other-buffer 1)
124
(if (= emacs "emacs")
125
(setq scroll-up-aggressively t)
126
(setq scroll-conservatively -4)) ;; <- change this
127
(other-buffer -1))
128
129
(defun show-max-other-window ()
130
(interactive)
131
(other-window 1)
132
(comint-show-maximum-output)
133
(other-window -1))
134
135
;; call this once
136
;; (ajr::scroll-to-end::peterD "xemacs")
137
;; (ajr::scroll-to-end::peterD "emacs")
138
139
(global-set-key [f11] 'show-max-other-window)
140
(global-set-key [f12] 'ess-eval-line-and-step))
141
142
143
; Provide package
144
145
(provide 'ess-r-a)
146
147
; Local variables section
148
149
;;; This file is automatically placed in Outline minor mode.
150
;;; The file is structured as follows:
151
;;; Chapters: ^L ;
152
;;; Sections: ;;*;;
153
;;; Subsections: ;;;*;;;
154
;;; Components: defuns, defvars, defconsts
155
;;; Random code beginning with a ;;;;* comment
156
157
;;; Local variables:
158
;;; mode: emacs-lisp
159
;;; outline-minor-mode: nil
160
;;; mode: outline-minor
161
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
162
;;; End:
163
164
;;; ess-r-a.el ends here
165
166