How to Enter Data into the R Text Editor - dummies

How to Enter Data into the R Text Editor

By Andrie de Vries, Joris Meys

Although R is primarily a programming language, R has a very basic data editor that allows you to enter data directly using the edit() function.

The edit() function is only available in some R code editors, so depending on which software you’re using to edit your R code, this approach may not work. As of this writing, this option is not yet supported by RStudio.

To use the R text editor, first you need to initiate a variable. For example, to create a data frame and manually enter some of the periodic table data, enter the following:

elements <- data.frame()
elements <- edit(elements)

This displays an interactive editor where you can enter data. Notice that because the data frame is empty, you can scroll left and right, or up and down, to extend the editing range. Notice also that the editor doesn’t allow you to modify column or row names.


Enter some data. Then to save your work, click the X in the top-right corner.

To view the details that you’ve just entered, use the print() function:

> print(elements)
 var1   var2 var3
1  1 Hydrogen  H
2  2  Helium  He
3  3 Lithium  Li