- Code: Select all
poly <- polygon.read.format('./shapefile')
Error in read.shapefile(filename) : object 'filename' not found
Looking at the function code it seems the local variable `filename` on line 6 is misnamed and should be `file` to match the function argument.
- Code: Select all
polygon.read.format
function (file, mode = "shape")
{
mode = toupper(mode)
if (mode == "SHAPE") {
if (requireNamespace("shapefiles", quietly = TRUE)) {
shapefile = read.shapefile(filename)
number = length(shapefile$shp$shp)
poly = NA
for (ipol in 1:number) {
polyset = shapefile$shp$shp[[ipol]]
poly = polygon.create(polyset$points[, 1], polyset$points[,
2], polygon = poly)
}
}
else {
cat("You must download the package 'shapefiles' first")
}
}
else {
cat("The only format available are:\n")
cat("SHAPE : ShapeFile Polygont format\n")
stop0("Unknown format : ", mode)
}
poly
}
<bytecode: 0x7fd564308438>
<environment: namespace:RGeostats>
Edit: Replacing the local variable name fixed the issue for me and function runs as intended.