expect_that looks for a regular expression that matches the error, so you need to avoid the square brackets so that they are interpreted literally, and not as a template definition:
expect_that(f2(x=1.4), throws_error("error \\[1\\]"))
seems to work.
Or you can specify fixed=TRUE :
expect_that(f2(x=1.4), throws_error("error [1]", fixed = TRUE))
Ben bolker
source share