.grd
is the header file for the native format of the raster package. As explained here, there is no gdal driver for that format, therefore you can't run gdal_translate on such files.
Two options to batch convert the files:
First option, create headers (does not duplicate the data)
Does not generate tiff files, but makes the files readable by most (all?) gis software.
library(raster)
files <- list.files('directory/with/files/to/convert', pattern = pattern = '^.*\\.grd$', full.names = TRUE)
makeHeader <- function(x){
b <- brick(x)
hdr(b, format = 'ENVI')
}
lapply(files, makeHeader)
Second option, read and write back to tiff (duplicates data)
files <- list.files('directory/with/files/to/convert', pattern = pattern = '^.*\\.grd$', full.names = TRUE)
convertToTiff <- function(x) {
b <- brick(x)
extension(x) <- '.tif'
dt <- dataType(b)
writeRaster(b, filename = x, datatype = dt)
}
lapply(files, convertToTiff)
GSAG -raster- (rwv): Golden Software ASCII Grid (.grd) GSBG -raster- (rw+v): Golden Software Binary Grid (.grd) GS7BG -raster- (rw+v): Golden Software 7 Binary Grid (.grd) NWT_GRD -raster- (rw+v): Northwood Numeric Grid Format .grd/.tab
Is your GDAL built with the driver, check withgdalinfo --formats
.