3

I am missing (or not aware) of a feature in ESS to run some R code on selected text. When editing a script, like

df1 <- data.frame(a=1:100,b=rnorm(100))

I often want to see head(df1) in my terminal. I'd like to be able to move the cursor to df1 and run an elisp function that sends head(df1) to the R terminal. Can you direct me to how to do that, please? If I can define a few R-functions in Elisp functions and assign them to shortcuts, it would often ease my workflow.

3

Here's a quick and dirty approach. Depending on what you want there's lots of room for improvement.

(defun head-at-point ()
  (interactive)
  (let ((target (thing-at-point 'symbol)))
    (ess-send-string (ess-get-process ess-local-process-name)
                     (concat "head(" target ")\n"))))
  • Thank you, Tyler! Just what I was looking for. – John Doe Oct 16 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.