uday
uday

Reputation: 6713

how to make a code break if max memory is reached

In RStudio, there are some occasions when the max memory is reached for some of my codes, e.g.

Warning messages:
1: In dlData$unique_id <- paste(dlData$institution_key,  ... :
  Reached total allocation of 16322Mb: see help(memory.size)
2: In dlData$unique_id <- paste(dlData$institution_key,  ... :
  Reached total allocation of 16322Mb: see help(memory.size)
3: In `$<-.data.frame`(`*tmp*`, "unique_id", value = c("100003|19920822",  ... :
  Reached total allocation of 16322Mb: see help(memory.size)
4: In `$<-.data.frame`(`*tmp*`, "unique_id", value = c("100003|19920822",  ... :
  Reached total allocation of 16322Mb: see help(memory.size)

Usually, in such case, the code still continues to run to the next step, but I am not sure if my code really ran fine. Is it possible to break the code if the max memory is reached, i.e any settings in R?

Upvotes: 3

Views: 71

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226192

You could make your code stop on any warning message by setting

options(warn=2)

If your code is otherwise clean enough (i.e., you never get any other warnings), then this should work fine. I don't know offhand of a way to catch just one specific warning.

Upvotes: 2

Related Questions