Uriel Cohen Priva



Editing R values

I stumbled upon an easy way to change functions, values and data tables in R. R options allow you to specify an editor. I have yet to check what the default is for windows, but for linux it’s vi. Since I am on the emacs side in the editor war, the first thing I did was to change the default from vi to emacs using the following command:

> options(editor="emacs")

Editing values now becomes really easy:

> myVector <- c("a", "b", "c")
> fix(myVector)

I changed the last value to “d” to get:

I now saved the file in emacs and left the editor. The values in R changed accordingly:

> myVector
[1] "a" "b" "d"

R allows to edit functions in a similar manner, and opens a spreadsheet-like editor for data tables. Additionally, you may want to change a value but not save the changes to the same object. R allows to do that using the “edit” function, instead of “fix” (used in the examples above).

> anotherVector <- edit(myVector)