It's good of you do share the piece of code where the the issue is happening, but for more complex issues like this you should create a reprex. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here: