0

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?

  • Attack the problem by getting the result from lapply and then trying to rbind bits of it. sps = lapply(data, rgdal::readOGR) and then rbind(sps[[1]], sps[[2]]) and so on. Without your data I don't think we can be more specific. – Spacedman Dec 4 '18 at 17:12
  • I've had a quick play with various rbinds of spatial polygons and other things and I can't replicate your error. – Spacedman Dec 4 '18 at 17:29
  • If you've solved the problem and you aren't willing to answer it as an answer or it wouldn't help anyone else please delete the question so the site has more useful questions and answers on it. Tx. – Spacedman Dec 5 '18 at 8:10
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.