Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.
having sample data for dt
to reproduce locally will help a lot to see what is going on with your code.