flow controls
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message = TRUE)
next statement
- skip 1 iteration
x <- 1:5
for (val in x) {
if (val == 3){
next
}
print(val)
}
break statement
- halt entire loop
x <- 1:5
for (val in x) {
if (val == 3){
break
}
print(val)
}
invisible(), warning()
- R equivalent of python’s pass statement
my_func <- function(x){
invisible()
}
my_func(100)
foo = function(){
# write this tomorrow
warning("You ran foo and I havent written it yet")
}
foo()