logo

DataEditR

DataEditR is a lightweight package to interactively view, enter or edit data in R. In this vignette we will explore some of the key features that are available through the data_edit() function.

Preparation

In order to get started with DataEditR, we will need to install the package from GitHub and load it into our current R session:

devtools::install_github("DillonHammill/DataEditR")
library(DataEditR)

1. Data Visualisation

Simply supply your data in the form of a matrix, data.frame or data.table to data_edit() to view it in an interactive table. For example, if we wanted to take a look at the mtcars dataset:

data_edit(mtcars)

The data editor will open in the RStudio viewer pane by default but this can be changed to a pop-up window by setting viewer = FALSE as below. Both of these options have optional support for displaying the data in a web browser as well.

data_edit(mtcars,
          viewer = FALSE)

The data editor will automatically move row names inside the table so that the row indices can be displayed on the left hand side. Once you are finished exploring the data, you can close the data editor by hitting the Save & Close button in the top left corner.

2. Data Import

data_edit() can all read in any form tabular data from file for viewing and editing. By default data_edit() will use read.csv from the utils package to read in files, but this can be changed to any reading function by supplying the name of the function to the read_fun argument. If you need to pass any additional arguments to your reading function, these can be supplied as a named list to the read_args argument. The data will be returned by data_edit() once the Save & Close button has been clicked.

mtcars <- data_edit("mtcars.csv",
                    read_fun = "read.csv",
                    read_args = list(header = TRUE))
head(mtcars)
#>                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

3. Data Manipulation

data_edit() has a variety of interactive data manipulation tools to edit your data. We will explore the use of each of these tools below:

3.1 Addition or removal of rows or columns

Rows or columns can be added to the data from within the data editor by right clicking on a cell within the table. This will display a context menu with the options to add or remove rows or columns.

data_edit(mtcars)

3.2 Rename rows or columns

data_edit() has full support for editing row and column names. Simply select the cell that you want to edit and update its value within the table. As outlined above, the row names will appear within the table so that the row indices can be displayed on the left-hand side. The row indices cannot be edited. The new row or column names must be unique!

data_edit(mtcars)