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 @@
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 @@ 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 @@ @@ -174,6 +174,13 @@