Can you send a reproducible example with information on the OS, packages, etc? We can't do much without that.
The best way to get help is to use the reprex
package with non-private data. This post has more information on how to do that but it can be as simple as copying your code to the clipboard and using reprex::reprex(si = TRUE)
.