I am trying to calculate the sum of line lengths within grid cells in R. I have been using this as a reference https://gis.stackexchange.com/questions/289350/calculate-sum-of-line-lengths-in-r
The problem I am having is that when I create a grid using st_make_grid, there is no ID column for when I match the line intersection lengths to the grid. I have tried using as.Spatial to convert the grid to a SpatialPolygonsDataFrame so that I can add columns, but then st_length and st_intersections won't work because the grid is no longer an "sf" object. What would be the best workaround to this?

