How to deal with character(0) in R

It will help if make a reproducible example of your problem. See FAQ: What's a reproducible example (`reprex`) and how do I do one? for advice on doing this.