DillonHammill / DataEditR

An Interactive R Package for Viewing, Entering Filtering and Editing Data
https://dillonhammill.github.io/DataEditR/
384 stars 40 forks source link

Different return value for cancel button #50

Closed DillonHammill closed 2 years ago

DillonHammill commented 2 years ago

Hi @DillonHammill - I really want to know whether the user exited using the Done or the Cancel button. At present there doesn't seem to be any way to do this if they haven't actually changed some data. Would it make sense to not return the data when the Cancel is pressed? Or is there another way of determining this from the calling process?

The scenario for me is:

  1. Get some data
  2. Make some proposed changes
  3. Use DataEditR for user to review or adjust
  4. Either proceed with the (adjusted) changes (Done) or back out and start again (Cancel).

At present I can't distinguish 'Done' with no change from 'Cancel' - meaning back out.

Originally posted by @sch56 in https://github.com/DillonHammill/DataEditR/issues/3#issuecomment-1111715072

DillonHammill commented 2 years ago

@sch56 I moved your request to a new issue where it is more visible. The current implementation returns the original data when the cancel button is hit: https://github.com/DillonHammill/DataEditR/blob/504d7faf89b6689255c1d797a8ccfc4d55f37b85/R/data_edit.R#L548

I implemented it this way because I needed this functionality in other packages. I could add a cancel argument which would allow you to customise the return value when cancel is hit by the user.

data_edit(mtcars, cancel = NA)
DillonHammill commented 2 years ago

@sch56, I just pushed a fix to the master branch on GitHub. Please pull it down and let me know how you go:

devtools::install_github("DillonHammill/DataEditR")
data_edit(mtcars, cancel = NA)

Note: Any return value is supported including matrices, data.frames, lists etc.