[ESS] Additional Functions to add to ess-rdired.

Shawn Way SW@y @end|ng |rom meco@com
Fri Nov 8 21:29:56 CET 2019

I've added to the functionality of the rdired screen to allow the structure to be viewed similar to the "v" button.  Attached is the modifications necessary for this.

diff --git a/lisp/ess-rdired.el b/lisp/ess-rdired.el
index 312a0f9a..0b79efcb 100644
--- a/lisp/ess-rdired.el
+++ b/lisp/ess-rdired.el
@@ -124,6 +124,7 @@ the function which prints the output for rdired.")
     (define-key map "x" #'ess-rdired-delete)
     (define-key map "v" #'ess-rdired-view)
     (define-key map "V" #'ess-rdired-View)
+    (define-key map "s" #'ess-rdired-structure)
     (define-key map "p" #'ess-rdired-plot)
     (define-key map "y" #'ess-rdired-type)
     (define-key map "\C-c\C-s" #'ess-rdired-switch-process)
@@ -232,6 +233,13 @@ details."
   (ess-execute (ess-rdired-get (tabulated-list-get-id))
                nil "R view" ))
+(defun ess-rdired-structure (&optional _button)
+  "View the object structure at point."
+  (interactive)
+  (ess-execute (ess-rdired-str (tabulated-list-get-id))
+               nil "R structure" ))

+(defun ess-rdired-str (name)
+  "Generate R code to get the structure of the variable NAME.
+This is complicated because some variables might have spaces in their names.
+Otherwise, we could just pass the variable name directly to *R*."
+  (concat "str(" (ess-rdired-altquote name) ")")
+  )
 (defun ess-rdired-quote (name)
   "Quote NAME if not already quoted."
   (if (equal (substring name 0 1) "\"")
     (concat "\"" name "\"")))
+(defun ess-rdired-altquote (name)
+  "Alternate quote NAME if not already quoted."
+  (if (equal (substring name 0 1) "\"")
+      name
+    (concat "`" name "`")))

Shawn Way, P.E.


More information about the ESS-help mailing list