0

I am trying to analyse data from http://orca.science.oregonstate.edu/1080.by.2160.monthly.hdf.vgpm.v.chl.v.sst.php

the code works on R in windows but not on a Mac. I downloaded a free trial for parallel desktop but it has ended and now I'm back to a Mac. Why is the exact code not working on a Mac? Is there a way I could fix this so I can run the code on a Mac? is it because its a hdf file?

library(raster)
library(rgdal)


Jan <- raster("vgpm.2018001.hdf")
extent(Jan) <- extent(-180, 180, -90, 90)
crs(Jan) <- "+proj=longlat +datum=WGS84"
NAvalue(Jan) <- -9999
SAZ <- extent(-180, 180, -60, -40)
NPP_Jan <- crop(Jan, SAZ)
NPP_Jan_mean <- cellStats(NPP_Jan, stat = 'mean', na.rm=TRUE)

I get an error on Mac when I try to open the hdf file using raster.

Jan <- raster("vgpm.2018001.hdf") 
Error in .local(.Object, ...) : Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer", : Cannot create a RasterLayer object from this file
liv
  • 73
  • 7
  • What does "doesn't work" mean exactly? Have you installed the [system requirements of the rgdal package](https://cran.r-project.org/web/packages/rgdal/index.html) on your Mac? – Roland Nov 14 '19 at 12:09
  • I think I have installed the right package for rgdal... rgdal: version: 1.3-4, (SVN revision 766) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01 Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/gdal GDAL binary built with GEOS: FALSE Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493] Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgdal/proj Linking to sp version: 1.3-1 – liv Nov 14 '19 at 12:24
  • I get an error on Mac when I try to open the hdf file using raster. Jan – liv Nov 14 '19 at 12:24
  • I tried to see if I could install the package again but its not available? install.packages("rgdal", dependencies = TRUE) Warning in install.packages : package ‘rgdal’ is not available (for R version 3.4.4) – liv Nov 14 '19 at 12:37
  • Just a guess, but your file probably have CRLF as line endings (windows default) which are not parsed properly under Mac which use simply LF (assuming recent Mac OS, it would be CR for older versions). Check your file line endings with an editor allowing to show that (notepad++, ultraedit, atom). – Tensibai Nov 14 '19 at 12:46
  • hi @Tensibai im not sure how you do that... – liv Nov 14 '19 at 15:07
  • You may find guidance here https://stackoverflow.com/questions/27810758/how-to-replace-crlf-with-lf-in-a-single-file (FYI I searched google with "convert crlf to lf", take it as will to help you searching for future cases) – Tensibai Nov 14 '19 at 19:27

0 Answers0