Is there a practical way to dput()
an sp
object in R?
When I try to do the following:
data(World, package = "tmap")
dput(World[1:10, ], file=(tempFile <- tempfile()))
World2 <- dget(tempFile)
I get:
> World2 <- dget(tempFile)
Error in parse(file = file, keep.source = keep.source) :
...\file14f4ee257b1:155:23: unexpected '<'
154: 9L, 10L, 12L, 14L, 16L, 17L), class = "data.frame")
155: , polygons = list(<
^
The <
is usually followed by S4 object of class structure("Polygons", package = "sp")>
, so dput()
apparently does not resolve these nested S4 objects.
The problem seems to be quite similar to this one, but the proposed solution does not work here.
For a solution, please assume that I do not have access to the file system.
EDIT: The more general question is, of course: How can I send a complete sp
object to the console?