diff --git a/DESCRIPTION b/DESCRIPTION index 414f5fc..1363286 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: DataEditR Title: An Interactive Editor for Viewing, Entering & Editing Data -Version: 0.0.5 -Date: 2020-07-30 +Version: 0.0.6 +Date: 2020-08-25 Authors@R: person(given = "Dillon", family = "Hammill", diff --git a/NEWS.md b/NEWS.md index fd3f6ad..d84ca54 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# DataEditR 0.0.6 + +* Add ability to pass column names to `data_edit()` to construct a template data.frame with pre-defined column names. + # DataEditR 0.0.5 * Fix row indices when rows are added or removed. diff --git a/R/data_edit.R b/R/data_edit.R index cb76943..c849764 100644 --- a/R/data_edit.R +++ b/R/data_edit.R @@ -140,36 +140,48 @@ data_edit <- function(x, # READ IN DATA if (is.null(dim(x))) { - # READ IN FILE - if (length(x) == 1) { - # FUNCTION - read_fun <- match.fun(read_fun) - # CHECK READ ARGUMENTS - if (!is.null(read_args)) { - if (!class(read_args) == "list") { - stop("read_args must be a named list of arguments for read_fun.") + # FILE/COLUMN NAMES + if(is.character(x)) { + # FILE NAME - SINGLE + EXTENSION + if(length(x) == 1 & all(nchar(file_ext(x)) != 0)) { + # FUNCTION + read_fun <- match.fun(read_fun) + # CHECK READ ARGUMENTS + if (!is.null(read_args)) { + if (!class(read_args) == "list") { + stop("read_args must be a named list of arguments for read_fun.") + } } + # READ ARGUMENTS + read_args <- c(list(x), read_args) + # EXTRA ARGUMENTS + extra_args <- list(...) + read_args <- c( + read_args, + extra_args[!names(extra_args) %in% names(read_args)] + ) + # CALL FUNCTION + x <- do.call(read_fun, read_args) + # COLUMN NAMES + } else { + x <- data.frame( + structure(rep(list(""), length(x)), + names = x), + check.names = FALSE, + stringsAsFactors = FALSE + ) } - # READ ARGUMENTS - read_args <- c(list(x), read_args) - # EXTRA ARGUMENTS - extra_args <- list(...) - read_args <- c( - read_args, - extra_args[!names(extra_args) %in% names(read_args)] - ) - # CALL FUNCTION - x <- do.call(read_fun, read_args) - # EMPTY MATRIX/DATA.FRAME - } else if (length(x) == 2) { - x <- matrix(rep("", prod(x)), - nrow = x[1], - ncol = x[2] - ) - x <- as.data.frame(x) + # DIMENSIONS + } else if(is.numeric(x)) { + x <- data.frame( + structure(rep(list(rep("", x[1])), x[2]), + names = paste0("V", seq_len(x[2]))), + check.names = FALSE, + stringsAsFactors = FALSE + ) } } - + # BIND ROWS if (!is.null(row_bind)) { # NEW ROWS @@ -585,7 +597,7 @@ data_edit <- function(x, quiet = TRUE ) } - + # RETURN ORIGINAL CLASS if ("matrix" %in% data_class) { x <- as.matrix(x) diff --git a/R/utilities.R b/R/utilities.R index 93841ff..adb2568 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -9,4 +9,13 @@ java_script <- function(...) { stop("The arguments for JS() must be a character vector") x <- paste(x, collapse = '\n') structure(x, class = unique(c("JS_EVAL", oldClass(x)))) +} + +## FILE_EXT -------------------------------------------------------------------- + +#' Get file extensions from file names +#' @noRd +file_ext <- function(x) { + pos <- regexpr("\\.([[:alnum:]]+)$", x) + ifelse(pos > -1L, substring(x, pos + 1L), "") } \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 752b453..72f0210 100644 --- a/README.Rmd +++ b/README.Rmd @@ -19,6 +19,8 @@ knitr::opts_chunk$set( [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![Travis build status](https://travis-ci.com/DillonHammill/DataEditR.svg?branch=master)](https://travis-ci.com/DillonHammill/DataEditR) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/DillonHammill/DataEditR?branch=master&svg=true)](https://ci.appveyor.com/project/DillonHammill/DataEditR) +[![CRAN status](https://www.r-pkg.org/badges/version/DataEditR)](https://CRAN.R-project.org/package=DataEditR) +[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) Manual data entry and editing in R can be tedious, especially if you have limited coding experience and are accustomed to using software with a Graphical User Interface (GUI). **DataEditR** is an R package that makes it easy to view, enter and edit data within R, due to its convenient interactive GUI that supports many of the data manipulation operations supported by other commonly used GUI-oriented software. If you are new to **DataEditR** visit https://dillonhammill.github.io/DataEditR/ to get started. diff --git a/README.md b/README.md index f544114..2b5eb1f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.re status](https://travis-ci.com/DillonHammill/DataEditR.svg?branch=master)](https://travis-ci.com/DillonHammill/DataEditR) [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/DillonHammill/DataEditR?branch=master&svg=true)](https://ci.appveyor.com/project/DillonHammill/DataEditR) +[![CRAN +status](https://www.r-pkg.org/badges/version/DataEditR)](https://CRAN.R-project.org/package=DataEditR) +[![Lifecycle: +stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) Manual data entry and editing in R can be tedious, especially if you @@ -103,7 +107,7 @@ citation("DataEditR") #> To cite package 'DataEditR' in publications use: #> #> Dillon Hammill (2020). DataEditR: An Interactive Editor for Viewing, -#> Entering & Editing Data. R package version 0.0.5. +#> Entering & Editing Data. R package version 0.0.6. #> https://github.com/DillonHammill/DataEditR #> #> A BibTeX entry for LaTeX users is @@ -112,7 +116,7 @@ citation("DataEditR") #> title = {DataEditR: An Interactive Editor for Viewing, Entering & Editing Data}, #> author = {Dillon Hammill}, #> year = {2020}, -#> note = {R package version 0.0.5}, +#> note = {R package version 0.0.6}, #> url = {https://github.com/DillonHammill/DataEditR}, #> } ``` diff --git a/docs/404.html b/docs/404.html index 244bb00..09dedbd 100644 --- a/docs/404.html +++ b/docs/404.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6 diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index 1d76579..5395131 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6 diff --git a/docs/articles/DataEditR.html b/docs/articles/DataEditR.html index b23b719..ea6149d 100644 --- a/docs/articles/DataEditR.html +++ b/docs/articles/DataEditR.html @@ -38,7 +38,7 @@ DataEditR - 0.0.5 + 0.0.6 @@ -94,18 +94,20 @@

DataEditR

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")
+

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

+
install.packages("DataEditR")
 library(DataEditR)
+

If you would like to use the development version of DataEditR it can be installed directly from GitHub:

+
devtools::install_github("DillonHammill/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)
+
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,
+
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.

@@ -113,7 +115,7 @@

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",
+
mtcars <- data_edit("mtcars.csv",
                     read_fun = "read.csv",
                     read_args = list(header = TRUE))
 head(mtcars)
@@ -133,38 +135,38 @@

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)
+
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)
+
data_edit(mtcars)

To prevent users from editing column names, set col_names = FALSE or supply the names of the columns that cannot be edited. For example, if we only wanted to prevent users from editing the name of the mpg column:

-
data_edit(mtcars,
+
data_edit(mtcars,
           col_names = "mpg")

3.3 Resize columns

To size columns, go to the right-hand border of the cell containing the name of that column and drag the cursor to the desired width.

-
data_edit(mtcars)
+
data_edit(mtcars)

3.4 Drag to fill

Values in cells can be dragged to other cells by selecting the filled cells and dragging the box in the lower right hand corner.

-
data_edit(mtcars)
+
data_edit(mtcars)

3.5 Append columns or rows

data_edit() can perform rbind and cbind operations internally to append new rows or columns to the data prior to editing. The new rows or columns should be supplied as a matrix or data.frame to the row_bind or col_bind arguments. If binding both rows and columns, it is important to note that rows are bound before columns.

-
# New column to add
+
# New column to add
 new_col <- matrix(rep(NA, nrow(mtcars)),
                   ncol = 1,
                   dimnames = list(NULL, "test"))
@@ -178,7 +180,7 @@ 

3.6 Read-only columns

If you would like to prevent values from being edited in certain columns, you can supply the names of the columns that cannot be edited to the col_readonly argument. Users will be able to edit values and the column name, but these will be reverted to the original values. For example, if we wanted to prevent the mpg column from being edited:

-
data_edit(mtcars,
+
data_edit(mtcars,
           col_readonly = "mpg")
@@ -190,22 +192,24 @@

4.1 Start with empty data.frame

If no data is supplied to data_edit() an empty data.frame will be constructed with a single row and column. You can then build your data.frame from scratch by adding new rows and columns and annotating the cells.

- +

4.2 Start with a template data.frame

Creating a data.frame from scratch as described above can be tedious, so instead we could start with a data.frame template that contains more rows or columns. To create a template data.frame, simply supply the required dimensions of the data.frame in the form c(nrow, ncol).

-
data_edit(c(3, 3))
+
data_edit(c(3, 3))

+

Alternatively, you can pass a vector of column names to create a data.frame template with pre-defined column names. You will need to install the development version DataEditR from GitHub to use this feature.

+
data_edit(c("Player", "Age", "Titles"))

5. Data saving

data_edit() will automatically return the edited data with appropriate column classes as an R object for use within R. Character columns are not converted to factors by default, but this can be changed by setting col_factor = TRUE.

-
# Add character column
+
# Add character column
 mtcars_new <- cbind(rownames(mtcars), mtcars)
 colnames(mtcars_new) <- "car"
 
@@ -227,7 +231,7 @@ 

#> $ gear: num 4 4 4 3 3 3 3 4 4 4 ... #> $ carb: num 4 4 1 1 2 1 4 2 2 4 ...

The edited data can also be written to a file of any format by specifying the name of the file to the save_as argument and specifying the name of the writing function to use through write_fun. The default is to use write.csv from the utils package. You can also pass any additional arguments to your write function in a named list to write_args.

-
mtcars_new <- data_edit(mtcars,
+
mtcars_new <- data_edit(mtcars,
                         save_as = "mtcars.csv",
                         write_fun = "write.table",
                         write_args = list(sep = ",",
@@ -241,7 +245,7 @@ 

6.1 Checkboxes

Checkboxes can be used to obtain TRUE or FALSE value inputs from users. The resulting data will have a value of TRUE or NA based on user input.

-
data_edit(mtcars,
+
data_edit(mtcars,
           col_bind = "fast",
           col_options = list(fast = c(TRUE,FALSE)))

@@ -250,7 +254,7 @@

6.2 Dropdown menus

Dropdown menus can be used to help prevent typing errors when set number of options are available for a column. For example, if we have a factor with levels Treatment-A, Treatment-B or Treatment-C it would be easier to select these options from a dropdown menu instead of having to manually type them. Dropdown menus can be added in the same way as checkboxes.

-
# Add column for car colour
+
# Add column for car colour
 data_edit(mtcars,
           col_bind = "col",
           col_options = list(col = c("red",
@@ -269,14 +273,14 @@ 

7.1 Stretch columns to fill page

If you would like to make full use of the space available to you, you can set col_stretch = TRUE to stretch the columns to fill the full width of the display.

-
data_edit(mtcars,
+
data_edit(mtcars,
           col_stretch = TRUE)

7.2 Logo and title

data_edit() does also have support for adding a logo and/or title to the data editor. For example, if you wanted to use data_edit() within your own package you can customise it with your package logo and instructions to the user through title.

-
car_logo <- 'https://raw.githubusercontent.com/DillonHammill/DataEditR/master/vignettes/DataEditR/DataEditR-Car.png'
+
car_logo <- 'https://raw.githubusercontent.com/DillonHammill/DataEditR/master/vignettes/DataEditR/DataEditR-Car.png'
 data_edit(mtcars,
           logo = car_logo,
           logo_size = 100,
@@ -287,7 +291,7 @@ 

7.3 Custom themes

data_edit() makes use of the shinythemes package to customise the appearance of the data editor. You can explore the different themes by supplying the name of a valid shinythemes theme to the theme argument.

-
data_edit(mtcars,
+
data_edit(mtcars,
           theme = "cosmo")

diff --git a/docs/articles/index.html b/docs/articles/index.html index 01276ec..0c149ab 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6
diff --git a/docs/authors.html b/docs/authors.html index d2424d8..5be85a0 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6
diff --git a/docs/index.html b/docs/index.html index fd95a18..3c0299c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@ DataEditR - 0.0.5 + 0.0.6
@@ -146,7 +146,7 @@

#> To cite package 'DataEditR' in publications use: #> #> Dillon Hammill (2020). DataEditR: An Interactive Editor for Viewing, -#> Entering & Editing Data. R package version 0.0.5. +#> Entering & Editing Data. R package version 0.0.6. #> https://github.com/DillonHammill/DataEditR #> #> A BibTeX entry for LaTeX users is @@ -155,7 +155,7 @@

#> title = {DataEditR: An Interactive Editor for Viewing, Entering & Editing Data}, #> author = {Dillon Hammill}, #> year = {2020}, -#> note = {R package version 0.0.5}, +#> note = {R package version 0.0.6}, #> url = {https://github.com/DillonHammill/DataEditR}, #> }

@@ -166,6 +166,8 @@

diff --git a/docs/news/index.html b/docs/news/index.html index 965c434..15f943d 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6
@@ -125,9 +125,18 @@

Changelog

Source: NEWS.md
+
+

+DataEditR 0.0.6 Unreleased +

+
    +
  • Add ability to pass column names to data_edit() to construct a template data.frame with pre-defined column names.
  • +
+

-DataEditR 0.0.5

+DataEditR 0.0.5 2020-08-12 +
  • Fix row indices when rows are added or removed.
  • Improve handling of duplicate row indices in case of accidental editing.
  • @@ -135,7 +144,8 @@

-DataEditR 0.0.4

+DataEditR 0.0.4 Unreleased +
  • Add col_readonly argument to prevent users from editing values or column names of certain columns.
  • Prevent error when column is clicked but not edited.
  • @@ -143,21 +153,24 @@

-DataEditR 0.0.3

+DataEditR 0.0.3 Unreleased +
  • Add col_names argument to allow control over which column names can be edited by the user.

-DataEditR 0.0.2

+DataEditR 0.0.2 Unreleased +
  • Fixes for CRAN submission.

-DataEditR 0.0.1

+DataEditR 0.0.1 Unreleased +
  • Add data_edit() to allow interactive data viewing, entry and editing.
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3e42adc..e9edef8 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 1.5.1 pkgdown_sha: ~ articles: DataEditR: DataEditR.html -last_built: 2020-08-09T07:21Z +last_built: 2020-08-25T00:11Z diff --git a/docs/reference/data_edit.html b/docs/reference/data_edit.html index 7c3fcbf..7a44099 100644 --- a/docs/reference/data_edit.html +++ b/docs/reference/data_edit.html @@ -83,7 +83,7 @@ DataEditR - 0.0.5 + 0.0.6
diff --git a/docs/reference/index.html b/docs/reference/index.html index 4a1c27d..8abcb29 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.5 + 0.0.6
diff --git a/vignettes/DataEditR.Rmd b/vignettes/DataEditR.Rmd index 246dd63..c4207b9 100644 --- a/vignettes/DataEditR.Rmd +++ b/vignettes/DataEditR.Rmd @@ -30,13 +30,18 @@ readr::write_lines(html, path = "logo.html") ## 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: +In order to get started with **DataEditR**, we will need to install the package from CRAN and load it into our current R session: ```{r, eval = FALSE} -devtools::install_github("DillonHammill/DataEditR") +install.packages("DataEditR") library(DataEditR) ``` +If you would like to use the development version of **DataEditR** it can be installed directly from GitHub: +```{r, eval = FALSE} +devtools::install_github("DillonHammill/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: @@ -188,6 +193,12 @@ data_edit(c(3, 3)) knitr::include_graphics('https://raw.githubusercontent.com/DillonHammill/DataEditR/master/vignettes/DataEditR/DataEditR-8.gif') ``` +Alternatively, you can pass a vector of column names to create a data.frame template with pre-defined column names. You will need to install the development version **DataEditR** from GitHub to use this feature. + +```{r, eval = FALSE} +data_edit(c("Player", "Age", "Titles")) +``` + ## 5. Data saving `data_edit()` will automatically return the edited data with appropriate column classes as an R object for use within R. Character columns are not converted to factors by default, but this can be changed by setting `col_factor = TRUE`.