I second @jdlong's suggestion to take a look at tryCatch for your specific case, but to answer the question more generally:
You seem to be looking for a branching flow control structure. In R, that's:
if (cond) cons.expr else alt.expr
(See: https://www.rdocumentation.org/packages/base/versions/3.4.3/topics/Control).
For your code:
if (file.exists(cool_dataset.csv)) {
df <- read_csv(cool_dataset.csv)
} else {
shell.exec(run_batchfile.bat)
Sys.sleep(60)
df <- read_csv(cool_dataset.csv)
}
Brackets are necessary for the multi-line style I used here, and in single-line style when you have more than one expression in a branch. Style guides (including the tidyverse style guide) often recommend defaulting to using brackets and multiple lines, and only using a single-line, no-bracket style if your statement is very simple.
ifelse is a function for conditional selection of elements. Roughly speaking, it returns a new object that is meant to have all the properties of the one you tested, except with element values chosen based on the outcome of the test. The dplyr version, if_else, is more strict about data types, and therefore has more predictable output.