Is there any ess function that does the following? Assume you have the line in Emacs like this

1 2 3 4

then once selected (e.g., using the mouse), it is transformed into


It would be a wonderful tool. I copy and paste stuff that I transform into vectors quite often. Also, it would be great to have a function that if you select

A B C D E 

it produces

"A", "B", "C", "D", "E"

1 Answer 1


Not a solution based on ess, but both of these are relatively simple to implement using Elisp.

For your first example, that is, 1 2 3 4 => c(1,2,3,4): use the Elisp functions format and replace-regexp-in-string to convert your data as text using a regular expression.

Put this Elisp command somewhere in your init.el:

(defun my-command (start end)
  (interactive "r")
      (format "c(%s)"
          "\\([[:digit:]]+\\) " 
          (buffer-substring-no-properties start end)))
      (delete-region start end))))

Mark a space-separated sequence of numbers, then invoke it with M-x my-command RET, or bind my-command to the key combination of your choice for easy access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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