Error in 1:nrow(SM) : argument of length 0

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. Much easier to give answers if the problem doesn't have to be reverse engineered.

I'd expect to see an a message like this is the SM object were missing, possibly, or were not a data frame.