[GIS] batch merge error: Error in match.arg(method) : ‘arg’ must be of length 1

mergerrgdalshapefile

I am attempting to read in a series of polygon shapefiles from a directory and batch merge them into a single shapefile. They all have the exact same field names. I am using this code:

all_data <- do.call(rbind, lapply(data, rgdal::readOGR))
#data is a list of files that exist in the directory, but it does not 
#contain all of the files in that directory. 

After reading in all of my files with readOGR, r returns this error and the bind fails:

Error in match.arg(method) : 'arg' must be of length 1 

any ideas about what might be causing this error?

Best Answer

Like Spacedman suggested, splitting the function into 2 lines corrected the problem. so:

all_data <- lapply(data, rgdal::readOGR)
all_data <- do.call(rbind, all_data)

Did what I expected it to do-- downloaded all of my shapefiles-- each containing one feature-- from the directory and merged the files into a single SPDF

Related Question