rsbivand / rgrass

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

initGRASS fails with "no stars SG yet" when SG is provided #23

Closed MiKatt closed 3 years ago

MiKatt commented 3 years ago

Since recently, initGRASS always fails with an error "no stars SG yet" when I provide it with an SG for DEFAULT_WIND. The SG provided is a SpatialGridDataFrame and I run use_sp before.

I think I traced down the problem to this part of the code

mSG <- !missing(SG)
    if (mSG) {
      if (!inherits(SG, "Spatial")) 
        stop("SG is of class", class(SG), "not inheriting from Spatial")
      R_in_sp <- isTRUE(.get_R_interface() == "sp")
      if (is.null(.get_R_interface())) 
        stop("run use_sp() before this function if SG is not missing")
      else stop("no stars SG yet")
    }

The last stop is always executed if .get_R_interface() is not null. As far as I see in the history this part was also recently changed.

I am running R 4.0.3, rgrass7 v. 0.2.4 and GRASS 7.8.5 on Linux Mint 19.

rsbivand commented 3 years ago

Thanks, the testing I was doing was with a missing SG. I guess the expected usage would be to test against R_in_sp and stop if it is "sf", so I'll try that first. Could you please provide a test example?

rsbivand commented 3 years ago

Please check my edit to see whether it fixes the problem (by running use_sp() if it hasn't been run, or if use_sf() has been run - without reverting subsequently. Should be silent if use_sp() has been run.

MiKatt commented 3 years ago

Thanks a lot! It behaves now as you describe. Here a test example:

devtools::install_github("rsbivand/rgrass7", force = TRUE)
library(rgrass7)
grass_program_path <-  "/usr/lib/grass78/" 
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
use_sp()
dem_grid <- rgdal::readGDAL(dem_path, silent = TRUE)
initGRASS(SG = dem_grid, mapset = "PERMANENT", gisBase = grass_program_path,
          remove_GISRC = TRUE,
          override = TRUE)

It runs silently with use_sp() and gives a warning without (Warning message: In initGRASS(SG = dem_grid, mapset = "PERMANENT", gisBase = grass_program_path, : use_sp() was set because SG was given).

rsbivand commented 3 years ago

Do you need a CRAN release soon, or is installing from github OK for now? The last CRAN submission was three weeks ago, so I'd prefer to wait for the next issues before releasing.

MiKatt commented 3 years ago

As initGRASS including SG is used within a function in the package openSTARS a quick CRAN release would be great. In the meantime, I will post a message to install rgrass7 from github when using openSTARS.

rsbivand commented 3 years ago

OK, I'll prepare a submission and explain why it is needed now.

rsbivand commented 3 years ago

Windows binary if needed on https://win-builder.r-project.org/DWxU2zQsKDLi/, starting submission.

rsbivand commented 3 years ago

"thanks, package rgrass7_0.2-5.tar.gz is on its way to CRAN."