Hi @snoopy! Welcome!
I can't see any way for that code to produce the error you describe, so I think it will help if you can explain more about exactly what you're doing. You might start by taking a look at our FAQ: Tips for writing R-related questions.
The best way for you to get help is to turn your question into a reproducible example. That way, you and your helpers can be sure you're all looking at the same thing!