diff --git a/DESCRIPTION b/DESCRIPTION index 1460069..4a5d256 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: DataEditR Title: An Interactive Editor for Viewing, Entering & Editing Data -Version: 0.0.3 +Version: 0.0.4 Date: 2020-07-30 Authors@R: person(given = "Dillon", diff --git a/NEWS.md b/NEWS.md index 5f0fe22..49ced01 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# DataEditR 0.0.4 + +* 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. + # DataEditR 0.0.3 * Add `col_names` argument to allow control over which column names can be edited by the user. diff --git a/R/data_edit.R b/R/data_edit.R index 2eb514f..a65b716 100644 --- a/R/data_edit.R +++ b/R/data_edit.R @@ -48,6 +48,9 @@ #' @param col_names logical indicating whether column names can be edited or a #' vector of column names that cannot be edited, set to TRUE by default to #' allow editing of column names. +#' @param col_readonly names of columns that cannot be edited. Users will be +#' able to edit values but these will be reverted to the original values. +#' Column names for these column cannot be edited either. #' @param row_bind additional rows to add to the data prior to loading into #' editor, can be either an array containing the new data, a vector containing #' the new row names for empty rows or a named list containing a vector for @@ -111,6 +114,7 @@ data_edit <- function(x, col_stretch = FALSE, col_factor = FALSE, col_names = TRUE, + col_readonly = NULL, row_bind = NULL, row_edit = TRUE, save_as = NULL, @@ -325,6 +329,14 @@ data_edit <- function(x, col_edit <- FALSE } + # READONLY COLUMNS + if(!is.null(col_readonly)) { + if(!all(col_readonly %in% colnames(x))) { + stop("'col_readonly' must contain valid column names.") + } + col_names <- col_readonly + } + # COLUMN NAMES - INDICES THAT CANNOT BE EDITED if(col_names == FALSE) { col_names <- colnames(x) @@ -354,7 +366,12 @@ data_edit <- function(x, # DATA EDITS - INCLUDES ROW NAME EDITS observeEvent(input$x, { + # OLD VALUES + x_old <- values[["x"]] values[["x"]] <- hot_to_r(input$x) + if(!is.null(col_readonly)){ + values[["x"]][, col_readonly] <- x_old[, col_readonly] + } }) # ROW/COLUMN NAME EDITS @@ -367,38 +384,41 @@ data_edit <- function(x, new_col_names <- unlist(input$x_changeHeaders[["colHeaders"]]) # COLUMN INDEX - COLUMNS CANNOT BE MOVED col_ind <- which(old_col_names != new_col_names) - # CUSTOM COLUMNS - KEEP COLUMN TYPE - if (!is.null(names(col_options))) { - if (any(old_col_names[col_ind] %in% names(col_options))) { - for (z in col_ind) { - if (old_col_names[z] %in% names(col_options)) { - ind <- match(old_col_names[z], names(col_options)) - names(col_options)[ind] <- new_col_names[z] + # ONLY UPDATE IF COLUMN NAMES CHANGE + if(length(col_ind) != 0) { + # CUSTOM COLUMNS - KEEP COLUMN TYPE + if (!is.null(names(col_options))) { + if (any(old_col_names[col_ind] %in% names(col_options))) { + for (z in col_ind) { + if (old_col_names[z] %in% names(col_options)) { + ind <- match(old_col_names[z], names(col_options)) + names(col_options)[ind] <- new_col_names[z] + } } } } - } - # EMPTY COLUMN NAMES - empty_col_names <- which(unlist(lapply(new_col_names, nchar) == 0)) - # APPLY COLUMN NAMES - RENDER - x_new <- hot_to_r(input$x) - colnames(x_new) <- new_col_names - values[["x"]] <- x_new - # REVERT EMPTY COLUMN NAMES TO ORIGINAL - RE-RENDER - if (length(empty_col_names) > 0) { - colnames(x_new)[empty_col_names] <- old_col_names[empty_col_names] + # EMPTY COLUMN NAMES + empty_col_names <- which(unlist(lapply(new_col_names, nchar) == 0)) + # APPLY COLUMN NAMES - RENDER + x_new <- hot_to_r(input$x) + colnames(x_new) <- new_col_names values[["x"]] <- x_new - # REVERT COLUMN NAME EDITS - } else if (length(col_names) > 0 & - old_col_names[col_ind] %in% col_names) { - if (quiet == FALSE) { - message( - paste0(paste(old_col_names[col_ind], collapse = " & "), - " column name(s) cannot be edited.") + # REVERT EMPTY COLUMN NAMES TO ORIGINAL - RE-RENDER + if (length(empty_col_names) > 0) { + colnames(x_new)[empty_col_names] <- old_col_names[empty_col_names] + values[["x"]] <- x_new + # PREVENT COLUMN NAME EDITS + } else if (length(col_names) > 0 & + old_col_names[col_ind] %in% col_names) { + if (quiet == FALSE) { + message( + paste0(paste(old_col_names[col_ind], collapse = " & "), + " column name(s) cannot be edited.") ) + } + colnames(x_new) <- old_col_names + values[["x"]] <- x_new } - colnames(x_new) <- old_col_names - values[["x"]] <- x_new } # ROW NAMES CANNOT BE EDITED } else if ("rowHeaders" %in% names(input$x_changeHeaders)) { diff --git a/README.Rmd b/README.Rmd index c3b2a99..752b453 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,8 +17,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) +[![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) 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 c43f37f..352cebd 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ 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) +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) +status](https://ci.appveyor.com/api/projects/status/github/DillonHammill/DataEditR?branch=master&svg=true)](https://ci.appveyor.com/project/DillonHammill/DataEditR) Manual data entry and editing in R can be tedious, especially if you @@ -103,7 +103,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.3. +#> Entering & Editing Data. R package version 0.0.4. #> https://github.com/DillonHammill/DataEditR #> #> A BibTeX entry for LaTeX users is @@ -112,7 +112,7 @@ citation("DataEditR") #> title = {DataEditR: An Interactive Editor for Viewing, Entering & Editing Data}, #> author = {Dillon Hammill}, #> year = {2020}, -#> note = {R package version 0.0.3}, +#> note = {R package version 0.0.4}, #> url = {https://github.com/DillonHammill/DataEditR}, #> } ``` diff --git a/docs/404.html b/docs/404.html index cd0c81e..e949b13 100644 --- a/docs/404.html +++ b/docs/404.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4 diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index f5c56c4..6e82af9 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4 diff --git a/docs/articles/DataEditR.html b/docs/articles/DataEditR.html index 6956794..f8fdba7 100644 --- a/docs/articles/DataEditR.html +++ b/docs/articles/DataEditR.html @@ -38,7 +38,7 @@ DataEditR - 0.0.3 + 0.0.4 @@ -174,6 +174,13 @@

col_bind = new_col)

+
+

+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,
+          col_readonly = "mpg")
+

@@ -183,14 +190,14 @@

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

@@ -198,7 +205,7 @@

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"
 
@@ -220,7 +227,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 et to 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 = ",",
@@ -234,7 +241,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 1 where TRUE was selected and NA for all other values.

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

@@ -243,7 +250,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",
@@ -262,14 +269,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,
@@ -280,7 +287,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 48d2011..3b79bfa 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4
diff --git a/docs/authors.html b/docs/authors.html index 1a581f1..7bb5a00 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4
diff --git a/docs/index.html b/docs/index.html index c6af9d9..70626f6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@ DataEditR - 0.0.3 + 0.0.4
@@ -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.3. +#> Entering & Editing Data. R package version 0.0.4. #> 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.3}, +#> note = {R package version 0.0.4}, #> url = {https://github.com/DillonHammill/DataEditR}, #> }

@@ -195,8 +195,8 @@

Developers

Dev status

  • Project Status: Active – The project has reached a stable, usable state and is being actively developed.
  • -
  • Travis build status
  • -
  • AppVeyor build status
  • +
  • Travis build status
  • +
  • AppVeyor build status
diff --git a/docs/news/index.html b/docs/news/index.html index 75656ba..cc72d84 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4
@@ -125,6 +125,14 @@

Changelog

Source: NEWS.md
+
+

+DataEditR 0.0.4

+
    +
  • 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.
  • +
+

DataEditR 0.0.3

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3ba02b1..d53de84 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-07-30T04:52Z +last_built: 2020-07-31T04:05Z diff --git a/docs/reference/data_edit.html b/docs/reference/data_edit.html index e623f85..7f9c462 100644 --- a/docs/reference/data_edit.html +++ b/docs/reference/data_edit.html @@ -83,7 +83,7 @@ DataEditR - 0.0.3 + 0.0.4
@@ -145,6 +145,7 @@

An interactive editor for viewing, entering & editing data

col_stretch = FALSE, col_factor = FALSE, col_names = TRUE, + col_readonly = NULL, row_bind = NULL, row_edit = TRUE, save_as = NULL, @@ -204,6 +205,12 @@

Arg

logical indicating whether column names can be edited or a vector of column names that cannot be edited, set to TRUE by default to allow editing of column names.

+ + + col_readonly +

names of columns that cannot be edited. Users will be +able to edit values but these will be reverted to the original values. +Column names for these column cannot be edited either.

row_bind diff --git a/docs/reference/index.html b/docs/reference/index.html index 566dee8..1aa0fa4 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -79,7 +79,7 @@ DataEditR - 0.0.3 + 0.0.4

diff --git a/man/data_edit.Rd b/man/data_edit.Rd index bea8a38..66e757e 100644 --- a/man/data_edit.Rd +++ b/man/data_edit.Rd @@ -12,6 +12,7 @@ data_edit( col_stretch = FALSE, col_factor = FALSE, col_names = TRUE, + col_readonly = NULL, row_bind = NULL, row_edit = TRUE, save_as = NULL, @@ -56,6 +57,10 @@ default.} vector of column names that cannot be edited, set to TRUE by default to allow editing of column names.} +\item{col_readonly}{names of columns that cannot be edited. Users will be +able to edit values but these will be reverted to the original values. +Column names for these column cannot be edited either.} + \item{row_bind}{additional rows to add to the data prior to loading into editor, can be either an array containing the new data, a vector containing the new row names for empty rows or a named list containing a vector for diff --git a/vignettes/DataEditR.Rmd b/vignettes/DataEditR.Rmd index 97fe30b..0208488 100644 --- a/vignettes/DataEditR.Rmd +++ b/vignettes/DataEditR.Rmd @@ -151,6 +151,15 @@ data_edit(mtcars, knitr::include_graphics('https://raw.githubusercontent.com/DillonHammill/DataEditR/master/vignettes/DataEditR/DataEditR-6.png') ``` +### 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: + +```{r, eval = FALSE} +data_edit(mtcars, + col_readonly = "mpg") +``` + ## 4. Data Creation You can also use `data_edit()` to interactively create data.frames from scratch without any coding.