library(raster)
## Loading required package: sp
p <- spPolygons(matrix(c(0, 0, 3, 3, 0,
0, 1, 1, 0, 0), ncol = 2),
matrix(c(0, 0, 3, 3, 0,
1, 3, 3, 1, 1), ncol = 2),
matrix(c(3, 3, 5, 5, 3,
0, 3, 3, 0, 0), ncol = 2),
attr = data.frame(x = c("a", "b", "c")))
plot_as_points <- function(x) points(coordinates(as(as(x, "SpatialLines"), "SpatialPoints")))
par(mfrow = c(2, 2))
plot(p); plot_as_points(p[1, ])
plot(p); plot_as_points(p[2, ])
plot(p); plot_as_points(p[3, ])
text(coordinates(p), label = p$x)
## now, we can coerce to lines and reconstruct
## (but this will only work because we have simple POLYGONs, with no holes)
noded_lines <- rgeos::gNode(as(p, "SpatialLinesDataFrame"))
## however, we now have a 3-part SpatialLines
## so this next bit might be ordering-prone
noded_p <- rgeos::gPolygonize(noded_lines)
## now, hope for the best and put the attributes back on
noded_polys <- SpatialPolygonsDataFrame(noded_p, as.data.frame(p))
par(mfrow = c(2, 2))

plot(noded_polys); plot_as_points(noded_polys[1, ])
plot(noded_polys); plot_as_points(noded_polys[2, ])
plot(noded_polys); plot_as_points(noded_polys[3, ])
text(coordinates(noded_polys), label = noded_polys$x)
