R - Error using dput with SpatialPolygonsDataFrame

Viewed 77

I use dput() and dget() to export and import data. I get an error when I import the exported text file of a SpatialPolygonsDataFrame.

Error in parse(file = file, keep.source = keep.source) :
MapFrance.txt:161:23: '<' inattendu(e) 160: ), row.names = c(NA, 96L), class = "data.frame") 161: , polygons = list(< ^

The error doesn't appear when I use a data frame. It works also with a SpatialPointsDataFrame.

The code is :

library(sp)
library(rgdal)
library(rgeos)

MyDirectory <- "" # fill with the directory

MapFrance <- readOGR(dsn = paste0(MyDirectory, "Departements"),  layer = "DEPARTEMENT")

dput(x = MapFrance, file = paste0(MyDirectory, "MapFrance.txt"))

Load_MapFrance <- dget(file = paste0(MyDirectory, "MapFrance.txt"))

The link to the geographic data (a SPH file) : https://drive.google.com/file/d/1wksMnkufQPdOfSbhWoZbPKMqlcLcll_j

0 Answers
Related