How would a person dput() an S4 object? I tried this
require(sp)
require(splancs)
plot(0, 0, xlim = c(-100, 100), ylim = c(-100, 100))
poly.d <- getpoly() #draw a pretty polygon - PRETTY!
poly.d <- rbind(poly.d, poly.d[1,]) # close the polygon because of Polygons() and its kin
poly.d <- SpatialPolygons(list(Polygons(list(Polygon(poly.d)), ID = 1)))
poly.d
dput(poly.d)
Notice that if I dput() an S4 object, I cannot reconstruct it again. Your thoughts?
As it currently stands, you cannot
dputthis object. The code ofdputcontains the following loop:This handles S4 objects recursively, but it relies on the assumption an S3 object will not contain an S4 object, which in your example does not hold:
Edit: Here is a work-around the limitations of
dput. It works for the example you provided, but I don’t think that it will work in general (e.g. it does not handle attributes).And here it is in action: