I'm trying to work with a raster file which has longitude extending from 20 to 380 degrees.
library(raster)
library(ncdf4)
raspH <- raster('~/Downloads/GLODAPv2.2016b_MappedClimatologies/GLODAPv2.2016b.pHts25p0.nc', varname = 'pHts25p0', band = 1)
raspH
class : RasterLayer
band : 1 (of 33 bands)
dimensions : 180, 360, 64800 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 20, 380, -90, 90 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : GLODAPv2.2016b.pHts25p0.nc
names : seawater.ph.reported.on.total.scale.at.standard.temperature..25C..and.pressure..0dbar.
z-value : 1
zvar : pHts25p0
plot(raspH)
The file (netcdf) is from the GLODAP project and can be downloaded here. I'd like to convert this to -180 to 180. Any advice? I imagine the easiest would be to change the longitude first to 0 to 260 degrees by subtracting 360 from all values >360 and then rotate, but how do I go ahead with changing the longitude values in the raster file?
I've also considered changing the longitude directly in the netcdf file, but that messes up the spacing, causing an error when I try to read the file into a raster object.
Any suggestions would be appreciated.

I figured this out based on the
rotatefunction in therasterpackageit omits several checks that are done in the
rotatefunction, but seems to do the job