I believe one of the lines of code you gave as the answer to Exercise 9.4 has a small typo in it.
You give a model answer as length(unique(symbols) == 1) but that doesn't return a logical as needed for the exercise.
I think you just have one of the brackets in the wrong place and it should be length(unique(symbols)) == 1.