So I just started to use the library rgrass7 from R and I got this error

Error in hist.default(v, main = main, plot = plot, ...) : invalid number of 'breaks'

Or, using the summary function, I get errors like:

NA's 1 1 1 1

So I was wondering what was wrong.Because I don't know if it's the function at this point or it's my GRASS session that is open, or anything at all.

The code that I used is pretty straightforward:

initGRASS(gisBase = "C:/GRASS/GRASS_GIS_7_3_svn", home = tempdir(), 
      gisDbase = "C:/Users/user/Desktop/data",
      location = "Thesis", mapset = "user" override=T)

 my_vmaps=execGRASS("g.list", parameters = list(type = "vector", pattern = "precip*"))

 hist(r1 )
  • Are you looking for hist(r) and not r1? – nebi Sep 3 '17 at 15:00
  • I just want to print a histogram for now of my rasters, because I realize readRast fetches a spatialGrid but the values of that variable (which is r1) are null, – George Nostradamos Sep 3 '17 at 15:07

Yeah, so the problem was that I had to set a region, either from R or from within GRASS. See the code below:

initGRASS(gisBase = "C:/GRASS/GRASS_GIS_7_3_svn", 
      home=tempdir(),gisDbase = "C:/Users/anna/Desktop/data",
      location = "Thesis",mapset = "user", override=T)

Now if one does not set the region, the result would be a matrix with NA values, that is because when you are using the execGRASS function, you are basically using the syntax and the functionality of GRASS which uses a region to execute diffrent functions, if you haven't set a region, or your data are off that boundary zone, you will probably have NA values where you should have actual values. That is something where you can find from the GRASS manual here or from here.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • 2
    Did you change your code accordingly ? – gisnside Sep 9 '17 at 8:25
  • @gisnside Well, yeah, see my edit – George Nostradamos Sep 9 '17 at 15:12
  • Thanks ! It will be useful for people having the same problem :) – gisnside Sep 9 '17 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.