86
86
(defvar ess-rdired-objects ".rdired.objects <- function(objs) {
87
if (length(objs)==0) {
88
88
\"No objects to view!\"
90
90
mode <- sapply(objs, function(my.x) {
91
eval(parse(text=(paste('data.class(',my.x,')',sep=''))))})
91
eval( parse( text=sprintf('data.class(get(\"%s\"))', my.x))) })
92
92
length <- sapply(objs, function(my.x) {
93
eval(parse(text=(paste('length(',my.x,')',sep=''))))
93
eval( parse( text=sprintf('length(get(\"%s\"))', my.x))) })
95
94
d <- data.frame(mode, length)
96
row.names(d) <- paste(' ', row.names(d), sep='')
96
var.names <- row.names(d)
98
## If any names contain spaces, we need to quote around them.
99
quotes = rep('', length(var.names))
100
spaces = grep(' ', var.names)
102
quotes[spaces] <- '\"'
103
var.names = paste(quotes, var.names, quotes, sep='')
104
row.names(d) <- paste(' ', var.names, sep='')
99
107
}; .rdired.objects(ls())"
194
202
(defun ess-rdired-object ()
195
"Return name of object on current line."
203
"Return name of object on current line.
204
Handle special case when object contains spaces."
197
206
(beginning-of-line)
204
(search-forward " ") ;assume space follows object name.
205
(buffer-substring-no-properties beg (1- (point)))))))
209
(cond ((looking-at " ") ; First line?
211
((looking-at "\"") ; Object name contains spaces?
215
(search-forward "\"")
216
(buffer-substring-no-properties beg (point))))
217
(t ;should be a regular object.
220
(search-forward " ") ;assume space follows object name.
221
(buffer-substring-no-properties beg (1- (point))))))))
207
223
(defun ess-rdired-edit ()
208
224
"Edit (fix) the object at point."
214
230
"View the object at point."
216
232
(let ((objname (ess-rdired-object)))
217
(ess-execute objname nil "R view" )))
233
(ess-execute (ess-rdired-get objname)
236
(defun ess-rdired-get (name)
237
"Generate R code to get the value of the variable name.
238
This is complicated because some variables might have spaces in their names.
239
Otherwise, we could just pass the variable name directly to *R*."
240
(concat "get(" (ess-rdired-quote name) ")")
243
(defun ess-rdired-quote (name)
244
"Quote name if not already quoted."
245
(if (equal (substring name 0 1) "\"")
247
(concat "\"" name "\"")))
219
250
(defun ess-rdired-View ()
220
251
"View the object at point in its own buffer.
221
252
Like `ess-rdired-view', but the object gets its own buffer name."
223
254
(let ((objname (ess-rdired-object)))
224
(ess-execute ;;(concat "edit(" objname ")\n")
256
(ess-rdired-get objname)
226
257
nil (concat "R view " objname ))))
228
259
(defun ess-rdired-plot ()
229
260
"Plot the object on current line."
231
262
(let ((objname (ess-rdired-object)))
232
(ess-command (concat "plot(" objname ")\n"))))
263
(ess-command (concat "plot(" (ess-rdired-get objname) ")\n"))))
234
265
(defun ess-rdired-type ()
235
266
"Run the mode() on command at point.
236
Named type because of similarity
237
with the dired command bound to y key."
267
Named type because of similarity with the dired command bound to
239
270
(let ((objname (ess-rdired-object))
240
271
;; create a temp buffer, and then show output in echo area
241
272
(tmpbuf (get-buffer-create "**ess-rdired-mode**")))
244
(ess-command (concat "mode(" objname ")\n") tmpbuf )
275
(ess-command (concat "mode(" (ess-rdired-get objname) ")\n")
245
277
(set-buffer tmpbuf)