In this paper, we propose a novel simultaneous localization and mapping algorithm, R-LIO, which combines rotating multi-line lidar and inertial measurement unit. R-LIO can achieve real-time and high-precision pose estimation and map-building. R-LIO is mainly composed of four sequential modules, namely nonlinear motion distortion compensation module, frame-to-frame point cloud matching module based on normal distribution transformation by self-adaptive grid, frame-to-submap point cloud matching module based on line and surface feature, and loop closure detection module based on submap-to-submap point cloud matching. R-LIO is tested on public datasets and private datasets, and it is compared quantitatively and qualitatively to the four well-known methods. The test results show that R-LIO has a comparable localization accuracy to well-known algorithms as LIO-SAM, FAST-LIO2, and Faster-LIO in non-rotating lidar data. The standard algorithms cannot function normally with rotating lidar data. Compared with non-rotating lidar data, R-LIO can improve localization and mapping accuracy in rotating lidar data.