Home > Software engineering >  How to stop R from stopping execution on error?
How to stop R from stopping execution on error?

Time:01-05

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

CodePudding user response:

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

CodePudding user response:

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

  • Related