rsbivand / rgrass

Interpreted interface between the GRASS geographical information system and R
https://rsbivand.github.io/rgrass/
26 stars 8 forks source link

Error when reading raster using read_RAST in rgrass v 0.4.1 #86

Closed bniebuhr closed 3 months ago

bniebuhr commented 6 months ago

Hi, @RRTogunov and I were trying to read rasters from a GRASS db into R and had issues when using read_RAST() from rgrass version 0.4.1 (the lastest, I guess?). We get the message that the layer was not found, even though we can find it with "g.list". When we "downgraded" the rgrass package to version 0.3.6, though, it worked perfectly. Anyone knows what might be the problem?

Here below an example which I expect to be reproducible:

#---
# version 0.3.6

packageurl <- "https://cran.r-project.org/src/contrib/Archive/rgrass/rgrass_0.3-6.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
require(rgrass)
require(terra)

# version
packageVersion("rgrass")

# initialize GRASS
grassdir <- system("grass --config path", intern = TRUE)
gisDB <- "." # giddb
loc <- "nc_basic_spm_grass7/" # name of the location
ms <- "PERMANENT" # name of the mapset
# connect
rgrass::initGRASS(gisBase = grassdir,
                  gisDbase = gisDB,
                  location = loc,
                  mapset = ms,
                  override = TRUE)

# test read raster into R
rgrass::execGRASS("g.region", raster = "elevation@PERMANENT")

r <- rgrass::read_RAST("elevation@PERMANENT")
plot(r)
# ok!

#---
# version 0.4.1

detach("package:rgrass")

install.packages("rgrass")
require(rgrass)
require(terra)

# version
packageVersion("rgrass")

# initialize GRASS
grassdir <- system("grass --config path", intern = TRUE)
gisDB <- "." # giddb
loc <- "nc_basic_spm_grass7/" # name of the location
ms <- "PERMANENT" # name of the mapset
# connect
rgrass::initGRASS(gisBase = grassdir,
                  gisDbase = gisDB,
                  location = loc,
                  mapset = ms,
                  override = TRUE)

# test read raster into R
rgrass::execGRASS("g.region", raster = "elevation@PERMANENT")

r <- rgrass::read_RAST("elevation@PERMANENT")
# Error in rgrass::read_RAST("elevation@PERMANENT") : 
#   elevation@PERMANENT not found

# check that the map exists
rgrass::execGRASS("g.list", type = "raster", pattern = "elevation")
# elevation

We're using GRASS 8.2.0 in a linux environmen:

version
#>                _                                          
#> platform       x86_64-pc-linux-gnu                        
#> arch           x86_64                                     
#> os             linux-gnu                                  
#> system         x86_64, linux-gnu                          
#> status         Patched                                    
#> major          4                                          
#> minor          2.2                                        
#> year           2022                                       
#> month          11                                         
#> day            10                                         
#> svn rev        83330                                      
#> language       R                                          
#> version.string R version 4.2.2 Patched (2022-11-10 r83330)
#> nickname       Innocent and Trusting

Created on 2024-03-15 with reprex v2.0.2

rsbivand commented 6 months ago

Please try the development version, remotes::install_github(rsbivand/rgrass), which I'll submit soon if you can confirm that it fixes your problem #84 .

bniebuhr commented 6 months ago

Hi @rsbivand I have just tried it, and yes, it does work now!

rsbivand commented 6 months ago

Thanks, I'll move to submit next week when back from the mountains (my responses posted from stations where the train has internet connections).

florisvdh commented 3 months ago

Version 0.4.2 was submitted 17 March (7defffa).