You can use the stopifnot() function from the base package as an assert statement in R.
According to R Documentation:
Ensures the Truth of R Expressions
If any of the expressions (in ... or exprs) are not all TRUE, stop is called, producing an error message indicating the first expression which was not (all) true.
stopifnot(..., exprs, local = TRUE)
any number of (typically but not necessarily logical) R expressions, which should each evaluate to (a logical vector of all) TRUE. Use either ... or exprs, the latter typically an unevaluated expression of the form
(only when exprs is used:) indicates the environment in which the expressions should be evaluated; by default the one where stopifnot() has been called from.
less_than_5 = function(x) return(x < 5)
for (i in 1:10)
Error: less_than_5(i) is not TRUE
The above code prints the numbers 1 through 5, then throw an error message.