DillonHammill / DataEditR

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

data_edit() crashes when code is highlighted before running #39

Closed Danny-dK closed 2 years ago

Danny-dK commented 2 years ago

This works: Drag select entire line and run.

mydata <- data_edit(code = "D:/data_recreate2.R", read_fun = "read.csv2")

But this doesn't (i.e. breaking the line): Drag select all lines and run.

mydata <- data_edit(code = "D:/data_recreate2.R", 
                    read_fun = "read.csv2")

It returns with error:

Warning in file(file, "rt") :
  cannot open file 'mydata <- data_edit(code = "D:/data_recreate2.R", 
read_fun = "read.csv2")': Invalid argument
Warning: Error in file: cannot open the connection
  61: file
  60: read.table
  59: read.csv2
  57: module
  52: callModule
  51: moduleServer
  50: dataInputServer
  49: server
Error in file(file, "rt") : cannot open the connection

it does run if I place the cursor on the first line (so not selecting anything) and then run.

Is that to be expected?

System: windows 10 R 4.1.2 Rstudio 2021.9.1.372 DataEditR 0.1.4

DillonHammill commented 2 years ago

I think the error is coming from specifying read_fun when you are not readying the data from file (i.e. you are in fact using an empty template). If you remove the read_fun part it should work fine. I will take a closer look to see if I put in a more permanent fix to prevent this from happening.

DillonHammill commented 2 years ago

@Danny-dK, I can't seem to replicate this issue on my machine but I have just pushed a fix that will hopefully fix the problem for you. Please pull down the latest version of DataEditR from GitHub and try again:

devtools::install_github("DillonHammill/DataEditR")
Danny-dK commented 2 years ago

Thanks @DillonHammill for looking into it. The read function is needed to tell the library what function to use when reading in the data in the graphical user interface (by clicking on the browse button): image

My csv is ; delimited, hence it requires csv2, the default of read.csv that DataEditR uses does not read the data in properly.

I found that it is not specifically a read_fun thing, but pertains mainly on drag selecting both lines and then running: image

(Note that in the above there is no read_fun)

But it does work fine by just clicking on the first line and then run.

I'll try the latest version and get back to you.

Danny-dK commented 2 years ago

Nope, the new version has the same

https://user-images.githubusercontent.com/45395070/146334633-a8536002-d2cc-4acf-9dfe-85bc17d6c4cc.mp4

I tried to screenrecord a short video which was in webm but I tried converting to mp4 (hopefully it plays okay).

The associated error in the console is:

Warning in file(file, "rt") :
  cannot open file 'test <- data_edit(x = NULL,
                  code = 'D:/create_table.R')
': Invalid argument
Warning: Error in file: cannot open the connection
  61: file
  60: read.table
  59: read.csv
  57: module
  52: callModule
  51: moduleServer
  50: dataInputServer
  49: server
Error in file(file, "rt") : cannot open the connection
DillonHammill commented 2 years ago

Thanks @Danny-dK, this is helpful - looks like the app is crashing as it is trying to read in NULL data for some reason. I will take a closer look. In the meantime, this should work just fine:

mydata <- data_edit(
      x = c(10,10),
      code = "D:/data_recreate2.R", 
      read_fun = "read.csv2"
)
Danny-dK commented 2 years ago

@DillonHammill yep that solves it! Tis a minor thing for me to add the table dimensions now that I know how to solve it.

DillonHammill commented 2 years ago

@Danny-dK, I just pushed another fix to GitHub. Please can you pull it down again and let me know if the original issue is resolved?

devtools::install_github("DillonHammill/DataEditR")
Danny-dK commented 2 years ago

@DillonHammill At least it doesn't crash now, but......

image

Just clicking the first line and running does run without problem (still specific to selecting lines and running).

DillonHammill commented 2 years ago

Ah I think I am onto the problem now, I will try and fix this today.

DillonHammill commented 2 years ago

OK, so the issue was actually coming from the RStudio addin side of things. Any highlighted text is treated as a dataset that should be passed to the data_edit() addin, obviously we don't want this behaviour when the entire data_edit() call is highlighted. I just pushed a fix to make sure the highlighted text is in fact an R object before trying to read it in as data. Please pull down the latest version of DataEditR from GitHub (version 0.1.5) and let me know how you go.

devtools::document("DillonHammill/DataEditR")
Danny-dK commented 2 years ago

@DillonHammill Awesome, it's solved. You can close this issue.

Thank you for looking into it. Also thank you for all the work on this library, it is much appreciated! (it will do wonders for my colleagues that are not experienced with R and are more used to graphical user interfaces) Keep up the good work! :)

DillonHammill commented 2 years ago

No worries! Thanks for reporting this issue.