The comments above are not correct.
In the spatstat
package, first convert your shapefile to an object of class "psp"
(planar segment pattern) as explained in the accompanying vignette on shapefiles.
Then use the function as.linnet
to convert the "psp"
object to a linear network object of class "linnet"
.
For more explanation, see chapter 17 of the spatstat book.