In R, I have been successfully using the sf package, st_write function to write sf objects to shapefile, using the ESRI shapefile driver). I understand that the st_write function relies on GDAL.
I need to write shapefiles with several character class attributes in the df. These are all writing with a default 80 character width, as expected. I need to write these attributes to narrower field widths.
From the GDAL page:
Field sizes The driver knows to auto-extend string and integer fields (up to the 255 bytes limit imposed by the DBF format) to dynamically accommodate for the length of the data to be inserted.
It is also possible to force a resize of the fields to the optimal width by issuing a SQL ‘RESIZE ’ via the data source ExecuteSQL() method. This is convenient in situations where the default column width (80 characters for a string field) is bigger than necessary.
I need to do exactly this and force a resize, but I don't understand how to implement a SQL RESIZE<tablename> via the data source ExecuteSQL() method. I am not fluent (or experienced) with SQL and thus don't know where to begin in R.
Does anyone have an example of doing this in R? Can you point me in the right direction or provide an example?