sf features that I have created/manipulated in R that I need to export to shapefile (my client only accepts shapefile format so I cannot use .gpkg or other formats). I have used
st_write to successfully save the features as a new file, however, the length of each attribute is the maximum length possible. How can I set the length for each attribute? The help file indicates that this is probably possible but I can't quite figure out how. I'm guessing that is it is in
dataset_options = NULL, layer_options = NULL.
Example using sample dataset
nc <- st_read(system.file("shape/nc.shp", package="sf")) st_write(nc[,c("AREA", "NAME", "CNTY_ID")], "nc_test2.shp",name=c("area", "name", "ID"))
All the numbers are considered as float/double values with the maximum length and precision and the text values have a length of 80. How can I set the length when doing the export? In SQL, the statement would be something like this:
ALTER COLUMN (NAME TYPE CHAR(20), AREA numeric(5, 3), CNTY_ID int(5))