I need to load multiple shape files into my R session. Currently, I am loading each shape file individually. This works, but it takes a long time and only uses 15% of my available CPU. Recently, I tried loading the shape files using ForEach and DoParallel:
require(foreach)
require(doParallel)
require(rgdal)
files <- c(
"AHVENANMAA/AHVENANMAA",
"ETELA-KARJALA/ETELA-KARJALA",
"ETELA-POHJANMAA/ETELA-POHJANMAA_1",
"ETELA-POHJANMAA/ETELA-POHJANMAA_2",
"ETELA-SAVO/ETELA-SAVO_1"
)
registerDoParallel(cores = 8)
listOfCurrentProvinces <- (
foreach(
x = files,
.packages = "rgdal",
.inorder = FALSE
) %dopar%
readOGR(x, layer = "DR_LINKKI")
)
This method works and is very fast (it uses 100% of my CPU). However, it uses up too much memory, especially when I repeat the process many times. Is there any way I can use ForEach and DoParallel without incurring such a major memory hit? My machine has 8 processors (4 physical and 4 logical) and has 16 GB of RAM.