0

I'm having an issue where if I execute several lines of code at once and one of them has an error, the lines below don't get executed.

For example if I have:

table(data$AGE)
table(dataREGION)
table(date$SEXE)

I get the table for the first line, and then

Error in table(dataREGION) : object 'dataREGION' not found
>

And the last line does not execute.

Does anyone know why it does that and how to fix it?

(I work with R 4.2.2 and RStudio 2022.12.0+353 "Elsbeth Geranium" Release)

Thanks! Have a nice day, Cassandra

Cassandra
  • 63
  • 4
  • 3
    You should look into 'error handling' as its not always obvious what R should do after an error. There's much discussion of error handling in R in other questions eg: https://stackoverflow.com/questions/2622777/exception-handling-in-r – George Savva Jan 04 '23 at 12:11

2 Answers2

2

Fixed: In Global Options > Console, under "Execution" uncheck the "Discard pending console input on error"

Cassandra
  • 63
  • 4
1

It seems like you want to use try().

try(table(data$AGE), silent = F, outFile = T) 
try(table(dataREGION)) # also works without any params
try(table(date$SEXE))

You can also use tryCatch() if you want more control but it doesn't seem necessary for your purpose.

__

As for why your dataREGION doesn't exectue:

Hazarding a guess it might be because you forgot the $ between data and REGION

D.J
  • 1,180
  • 1
  • 8
  • 17
  • It's not really what i want? My issue is that it used to excute code even past a line with an error a couple weeks ago and now it doesn't. I'd like to go back to the way it was --- Yeah, the dataREGION bite was just to provide a short exemple ahah – Cassandra Jan 04 '23 at 12:42
  • An error **always** stops R from running **if not handled** in some way - that is the point of an error. – D.J Jan 04 '23 at 12:46
  • 1
    No @DJ, here she is running one line at the time so it should run the next one. The error is caused by the Rstudio update – jrdavalos Jan 04 '23 at 13:27
  • @jrdavalos good to know, thanks for pointing it out - will check the R-Studio documentation – D.J Jan 04 '23 at 13:40