Skip to content

Commit

Permalink
DataEditR v0.0.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonHammill committed Jul 31, 2020
1 parent 96e6c60 commit b043c4d
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 56 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
72 changes: 46 additions & 26 deletions R/data_edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![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)
<!-- badges: end -->

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.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- badges: end -->

Manual data entry and editing in R can be tedious, especially if you
Expand Down Expand Up @@ -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
Expand All @@ -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},
#> }
```
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b043c4d

Please sign in to comment.