0

I'm trying to set a crs and evaluate min and max for a dataset, but I keep getting an error. My hunch is that something went wrong when I was setting the DSM_HARV, because although it ran without error, it's not functioning properly when I try to use it by name in code.

Here is the error message I'm receiving:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘setMinMax’ for signature ‘"character"’

Here is my code:

library(raster)
library(rgdal)

raster("HARV_dsmCrop.tif")

DSM_HARV <- "HARV_dsmCrop.tif"

DSM_HARV <- setMinMax(DSM_HARV) 
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
J Elliott
  • 1
  • 1
  • Welcome to StackOverflow! For code debugging please always ask with reproducible data per the [MCVE](https://stackoverflow.com/help/mcve) requirement. If there's no error on reproducible data then focus on the difference between your data and the example data to find the problem. – Hack-R Jun 19 '18 at 18:07
  • 1
    @Hack-R ... go ahead and point OP to your canonical question: [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269/1422451). – Parfait Jun 19 '18 at 18:23
  • @Parfait Will do – Hack-R Jun 19 '18 at 18:33

1 Answers1

0

The error message is relatively clear:

unable to find an inherited method for function ‘setMinMax’ for signature ‘"character"’

You are trying to use the setMinMax function on a character (string) value. That makes no sense. The word "HARV_dsmCrop.tif" has no min and max numerical values.

You could do

library(raster)
DSM_HARV <- raster("HARV_dsmCrop.tif")
DSM_HARV
DSM_HARV <- setMinMax(DSM_HARV) 
DSM_HARV

But it might not be necessary to use setMinMax as these values may be known already from the tif file.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63