palr package has a function
image_raster for the task of baking in the palette to RGB version of the raster. (You can set the extent and projection using raster itself as usual).
#> Loading required package: sp
## apply the colours used by raster plot() itself
rgb0 <- image_raster(r, col = rev(terrain.colors(255)))
Created on 2020-05-22 by the reprex package (v0.3.0)
There are arguments to control the
raster::writeRaster() to create a GeoTIFF (or other format).
(To create PNG or JPEG I would convert the raster to array and use
jpeg packages, just fwiw)