first <- 3
second <- 5
third <- 7
if (third >= first && third >= second) {
cat("nothing is larger than third\n")
}
# nothing is larger than third
if (!(first >= second || first >= third)) {
cat("first is the smallest\n")
}
# first 最小
# 不支持链式比较:两部分都要写出来
if (first < second && second < third) {
cat("second is between first and third\n")
}
# second 在 first 和 third 之间
# 陷阱:链式写法是语法错误
chain_error <- tryCatch(
parse(text = "1 < 2 < 3"),
error = conditionMessage)
cat("chain_error =", chain_error, "\n")
# chain_error = <text>:1:7: unexpected '<'
# 1: 1 < 2 <
# ^