Using publicly available sea area shapefiles
bahamas: http://www.marineregions.org/gazetteer.php?p=details&id=8404 ("eez.zip")
watl: http://www.marineregions.org/gazetteer.php?p=details&id=7135 ("iho_quadrants.zip")
gom: http://www.marineregions.org/gazetteer.php?p=details&id=4288
I joined the Bahamas to the Western Atlantic
watl <- read_sf("iho_quadrants_20150810.shp")
bahamas <- read_sf("eez.shp")
watlbah <- st_union(watl, bahamas)
Then removed overlapping areas with the Gulf of Mexico
watlbahamas <- st_difference(watlbah, GOM)
and the Slope Sea. File: https://drive.google.com/open?id=1eDmn8k3cHqhrqdLdLr8wKDYmnDRid_NQ
slopesea <- read_sf(slopesea.GPKG)
watlbahamas <- st_difference(watlbahamas, slopesea)
Then saved the result
st_write(obj = watlbahamas, dsn = "watlbahamas.GPKG")
Which resulted in the following:
Error in st_write.sf(obj = watlbahamas, dsn = "watlbahamas.GPKG") :
failed writing to temporary file /tmp/RtmpgG9ykj/file15ca4a4711fe.GPKG
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :
GDAL Error 1: sqlite3_exec(CREATE TABLE "watlbahamas" ( "fid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "geom" GEOMETRY, "name" TEXT, "id" TEXT, "bearings" TEXT, "name_1" TEXT, "mrgid_1" MEDIUMINT, "name_2" TEXT, "mrgid_2" MEDIUMINT, "name_3" TEXT, "mrgid_3" MEDIUMINT, "mrgid" REAL, "geoname" TEXT, "mrgid_ter1" REAL, "pol_type" TEXT, "mrgid_sov1" REAL, "territory1" TEXT, "iso_ter1" TEXT, "sovereign1" TEXT, "mrgid_ter2" REAL, "mrgid_sov2" REAL, "territory2" TEXT, "iso_ter2" TEXT, "sovereign2" TEXT, "mrgid_ter3" REAL, "mrgid_sov3" REAL, "territory3" TEXT, "iso_ter3" TEXT, "sovereign3" TEXT, "x_1" REAL, "y_1" REAL, "mrgid_eez" REAL, "area_km2" REAL, "name.1" TEXT, "id.1" TEXT, "longitude" REAL, "latitude" REAL, "min_x" REAL, "min_y" REAL, "max_x" REAL, "max_y" REAL, "area" REAL, "mrgid.1" MEDIUMINT, "Id" MEDIUMINT)) failed: duplicate column name: Id
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :
GDAL Error 1: failed to prepare SQL: SELECT "fid", ST_MinX("geom"), ST_MaxX("geom"), ST_MinY("geom"), ST_MaxY("geom") FROM "watlbahamas" WHERE "geom" NOT NULL AND NOT ST_IsEmpty("geom")
3: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :
GDAL Error 1: sqlite3_exec(DROP TABLE "watlbahamas") failed: no such table: watlbahamas
4: In CPL_write_ogr(obj, tmp, layer, driver, as.character(dataset_options), :
GDAL Error 1: sqlite3_exec(CREATE TABLE "watlbahamas" ( "fid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "geom" GEOMETRY, "name" TEXT, "id" TEXT, "bearings" TEXT, "name_1" TEXT, "mrgid_1" MEDIUMINT, "name_2" TEXT, "mrgid_2" MEDIUMINT, "name_3" TEXT, "mrgid_3" MEDIUMINT, "mrgid" REAL, "geoname" TEXT, "mrgid_ter1" REAL, "pol_type" TEXT, "mrgid_sov1" REAL, "territory1" TEXT, "iso_ter1" TEXT, "sovereign1" TEXT, "mrgid_ter2" REAL, "mrgid_sov2" REAL, "territory2" TEXT, "iso_ter2" TEXT, "sovereign2" TEXT, "mrgid_ter3" REAL, "mrgid_sov3" REAL, "territory3" TEXT, "iso_ter3" TEXT, "sovereign3" TEXT, "x_1" REAL, "y_1" REAL, "mrgid_eez" REAL, "area_km2" REAL, "name.1" TEXT, "id.1" TEXT, "longitude" REAL, "latitude" REAL, "min_x" REAL, "min_y" REAL, "max_x" REAL, "max_y" REAL, "area" REAL, "mrgid.1" MEDIUMINT, "Id" MEDIUMINT)) failed: duplicate column name: Id
5: In CPL_write_ogr(obj, tmp, layer, driver, as.character(dataset_options), :
GDAL Error 1: failed to prepare SQL: SELECT "fid", ST_MinX("geom"), ST_MaxX("geom"), ST_MinY("geom"), ST_MaxY("geom") FROM "watlbahamas" WHERE "geom" NOT NULL AND NOT ST_IsEmpty("geom")
6: In CPL_write_ogr(obj, tmp, layer, driver, as.character(dataset_options), :
GDAL Error 1: sqlite3_exec(DROP TABLE "watlbahamas") failed: no such table: watlbahamas
So I tried to simplify the object (https://gis.stackexchange.com/a/243576/16071):
watlbahamas <- rmapshaper::ms_simplify(input = as(watlbahamas, 'Spatial')) %>%
st_as_sf()
But the install fails (I can debug this but want to know if I'm on the right track first). Trying a different way:
watlbahamas <- rgeos::gSimplify(watlbahamas, tol = 0.1) %>%
st_as_sf()
# Error in rgeos::gSimplify(watlbahamas, tol = 0.1): no slot of name "proj4string" for this object of class "sf"
I feel like I've done a relatively simple operation but either there are elements which cause downstream problems in st_difference, or, more likely, I've gone about this the wrong way.
So (notwithstanding some typos from my trying to remove some text bulk) it seems the slope sea file is the culprit, and that st_difference on only GOM works fine.
Could it be that two+ st_difference calls create >1 set of the same named columns?

st_write(obj = watlbahamasTMP, dsn = watlbahamas.GPKG)but not shown us whatwatlbahamasTMPis, and you've not quoted the file name. Savingwatlbahamasas in your code works for me so I think you've probably not really done what you say you've done.... – Spacedman Jul 03 '19 at 19:21GOMbut I assume itsGOM = st_read("iho.shp")whereiho.shpis the download from the third of your list of links? – Spacedman Jul 04 '19 at 06:43readSFcome from? – Spacedman Jul 04 '19 at 06:44readSFnotread_sfin your code. – Spacedman Jul 05 '19 at 22:06