I have a polygon and two lines. How can I remove the portion of each line that falls within the polygon?
# polygon
coords <- matrix(c(-1.798123, -1.793072, -1.805767, -1.804129, -1.798123, 55.68066, 55.67369, 55.67508, 55.68139, 55.68066), ncol=2)
myPolygon <- Polygons(list(Polygon(coords)), "myPolygon")
myPolygon <- SpatialPolygons(list(myPolygon))
proj4string(myPolygon) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
plot(myPolygon)
# lines
line1 <- matrix(c(-1.79880, -1.79517, 55.67737, 55.67920), ncol=2)
line2 <- matrix(c(-1.80231, -1.80679, 55.67764, 55.68004), ncol=2)
line1L <- Line(line1)
line2L <- Line(line2)
my.lines <- Lines(list(line1L, line2L), ID="my.lines")
myLines <- SpatialLines(list(my.lines))
proj4string(myLines) <- CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
plot(myLines, add=T)

rgeospackage – Curlew Jun 06 '13 at 21:06