I am trying to read 39 json files into a common sf dataset in R.
Here is the method I've been trying:
path <- "~/directory"
file.names <- as.list(dir(path, pattern='.json', full.names=T))
geodata <- do.call(rbind, lapply(file.names, st_read))
The problem is in the last line: rbind
cannot work because the files have different numbers of columns. However, they all have three columns in common, and which I care about: MOVEMENT_ID
, DISPLAY_NAME
and geometry
. How could I select only these three columns when running st_read?
I've tried running geodata<-do.call(rbind, lapply(file.names, st_read,select=c('MOVEMENT_ID', 'DISPLAY_NAME', 'geometry')))
but, in this case, st_read
does not seem to recognise the geometry column (error: 'no simple features geometry column pressent').
I've also tried to use fread
in place of st_read
but this doesn't work as fread
is not adapted to spatial data.