r-spatial / link2GI

Simplify the linking of GIS/RS and CLI tools
https://r-spatial.github.io/link2GI
GNU General Public License v3.0
25 stars 7 forks source link

link2GI seems to "break" the link made by rgrass7 between R and GRASS #41

Closed lovalery closed 5 months ago

lovalery commented 4 years ago

@gisma @rsbivand Dear Chris,

On Roger's advice, I'm contacting you to report a problem I just highlighted: there seems to be a conflict between link2GI and rgrass7.

More precisely, when I have established a link between R and GRASS with the command rgrass7::initGRASS() and then run the command link2GI::linkOTB(), the link between R and GRASS seems to be broken: if I run the command rgrass7::initGRASS() again, R returns the following error message :

>> Error in if (is.na(projstr)) uprojargs <- projstr else uprojargs <- paste(unique(unlist(strsplit(projstr,  :
>>   l'argument est de longueur nulle
>> De plus : There were 50 or more warnings (use warnings() to see the first 50)

This error message is accompanied by a message that opens in a popup window :

> The procedure entry point GEOSMakeValid_r could not be located in the dynamic link library C:\Program Files\GRASS GIS 7.8\extrabin\gdal300.dll

Some information about the environment : -OS: Windows 8.1 -R version 3.6.3 -All the packages are up to date -the GRASS version: stand-alone Windows GRASS 7.8.3

To be a little more concrete and to help you identify the problem, below are two tests. I am at your disposal if you would like more information or if you would like me to carry out further tests. Best regards, Loïc

TEST 1 : 
1-Running initGRASS() 3 times: everything works fine the 3 times
2-Running linkOTB() 
3-Running initGRASS() : this crashes on the first attempt.

**initGRASS()-RUN 1**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**initGRASS()-RUN 2**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**initGRASS()-RUN 3**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**RUNNING link2GI::linkOTB()**
> # Link to OTB software v."LSGRM"
> OTB_LSGRM<-linkOTB(bin_OTB = "D:/Logiciel_OTB_LSGRM/bin",
+                    root_OTB = "D:/Logiciel_OTB_LSGRM",
+                    searchLocation= "D:", ver_select=TRUE, returnPaths=TRUE)
Please choose one:  2

> OTB_LSGRM
$pathOTB
[1] "D:\\Logiciel_OTB_LSGRM\\bin\\"

$version
                                    binDir                           baseDir installation_type
1 D:\\Logiciel OTB\\OTB-7.0.0-Win64\\bin\\ D:\\Logiciel OTB\\OTB-7.0.0-Win64               OTB
2            D:\\Logiciel_OTB_LSGRM\\bin\\            D:\\Logiciel_OTB_LSGRM               OTB

$exist
[1] TRUE

**initGRASS()-RUN 4**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

Error in if (is.na(projstr)) uprojargs <- projstr else uprojargs <- paste(unique(unlist(strsplit(projstr,  : 
  l'argument est de longueur nulle
De plus : Warning messages:
1: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'g.region.exe -g -3' renvoie un statut 313
2: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'g.proj.exe -j -f' renvoie un statut 313

The second test starting with link2GI::linkOTB() :

TEST 2 :
1-Running link2GI::linkOTB() 
2-Running initGRASS() 3 times: everything works fine the 3 times
3-Running link2GI::linkOTB() 
4-Running initGRASS() : this crashes on the first attempt.

**RUNNING link2GI::linkOTB()**
> # Link to OTB software v."LSGRM"
> OTB_LSGRM<-linkOTB(bin_OTB = "D:/Logiciel_OTB_LSGRM/bin",
+                    root_OTB = "D:/Logiciel_OTB_LSGRM",
+                    searchLocation= "D:", ver_select=TRUE, returnPaths=TRUE)
Please choose one:  2
> OTB_LSGRM
$pathOTB
[1] "D:\\Logiciel_OTB_LSGRM\\bin\\"

$version
                                    binDir                           baseDir installation_type
1 D:\\Logiciel OTB\\OTB-7.0.0-Win64\\bin\\ D:\\Logiciel OTB\\OTB-7.0.0-Win64               OTB
2            D:\\Logiciel_OTB_LSGRM\\bin\\            D:\\Logiciel_OTB_LSGRM               OTB

$exist
[1] TRUE

**initGRASS()-RUN 1**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**initGRASS()-RUN 2**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**initGRASS()-RUN 3**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

gisdbase    temp/GRASS_tmp 
location    file149c3d8c3aba 
mapset      PERMANENT 
rows        1 
columns     1 
north       1 
south       0 
west        0 
east        1 
nsres       1 
ewres       1 
projection  NA

**RUNNING link2GI::linkOTB()**
> # Link to OTB software v."LSGRM"
> OTB_LSGRM<-linkOTB(bin_OTB = "D:/Logiciel_OTB_LSGRM/bin",
+                    root_OTB = "D:/Logiciel_OTB_LSGRM",
+                    searchLocation= "D:", ver_select=TRUE, returnPaths=TRUE)
Please choose one:  2

> OTB_LSGRM
$pathOTB
[1] "D:\\Logiciel_OTB_LSGRM\\bin\\"

$version
                                    binDir                           baseDir installation_type
1 D:\\Logiciel OTB\\OTB-7.0.0-Win64\\bin\\ D:\\Logiciel OTB\\OTB-7.0.0-Win64               OTB
2            D:\\Logiciel_OTB_LSGRM\\bin\\            D:\\Logiciel_OTB_LSGRM               OTB

$exist
[1] TRUE

**initGRASS()-RUN 4**
> initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
+                   home="temp/GRASS_tmp", use_g.dirseps.exe=F, 
+                   gisDbase="temp/GRASS_tmp", mapset="PERMANENT", 
+                   remove_GISRC=T, override=T)

Error in if (is.na(projstr)) uprojargs <- projstr else uprojargs <- paste(unique(unlist(strsplit(projstr,  : 
  l'argument est de longueur nulle
De plus : Warning messages:
1: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'g.region.exe -g -3' renvoie un statut 313
2: In system(syscmd, intern = intern, ignore.stderr = ignore.stderr,  :
  l'exécution de la commande 'g.proj.exe -j -f' renvoie un statut 313
gisma commented 4 years ago

Dear Loïc unfortunately this is a "not so easy to figure out issue" due to the fact that link2GI was originally designed to simplify the difficult setup of GRASS from R overcome some minor problems of the direct linking using spgrass6 and rgrass7 under Windows. This is done by setting the missing environment parameters (depending on the Win Version) in a hidden R environment. So actually it was *never meant to mix rgrass7::initGRASS() with any of the link2GI functions.

Now your issue :

Edit: Sorry, just saw it Win 8.x while I'm dealing with this kind of thing, there hasn't been a machine with a windows 8.x installation that has worked properly or as expected, and I admit that my perhaps somewhat offensive standard message is: "Please install a clean Windows 10". cheers Chris

lovalery commented 4 years ago

Dear Chris, Thank you very much for your elaborated reply. Please find my answers to the various points you raise.

  1. This behaviour is a bit weird. I just tested again and I still have the problem I described in my previous message. Maybe the problem is related to Windows 8.1? (Sorry, I just saw your edit : so, I guess this is the origin of the problem). Anyway, here are the details of my R session with which I just reproduced the problem :
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgrass7_0.2-1 XML_3.99-0.3  link2GI_0.4.3 raster_3.3-7  rgeos_0.5-3   rgdal_1.5-12  sp_1.4-2     

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0   xfun_0.15          remotes_2.1.1      purrr_0.3.4        sf_0.9-4           lattice_0.20-41    vctrs_0.3.1        generics_0.0.2    
 [9] testthat_2.3.2     usethis_1.6.1      rlang_0.4.7        pkgbuild_1.0.8     e1071_1.7-3        pillar_1.4.6       glue_1.4.1         withr_2.2.0       
[17] DBI_1.1.0          sessioninfo_1.1.1  lifecycle_0.2.0    stringr_1.4.0      devtools_2.3.0     codetools_0.2-16   memoise_1.1.0      knitr_1.29        
[25] callr_3.4.3        ps_1.3.3           class_7.3-15       fansi_0.4.1        Rcpp_1.0.5         KernSmooth_2.23-16 backports_1.1.8    classInt_0.4-3    
[33] desc_1.2.0         pkgload_1.1.0      fs_1.4.2           digest_0.6.25      stringi_1.4.6      processx_3.4.3     dplyr_1.0.0        grid_3.6.3        
[41] rprojroot_1.3-2    cli_2.0.2          tools_3.6.3        magrittr_1.5       tibble_3.0.3       crayon_1.3.4       pkgconfig_2.0.3    ellipsis_0.3.1    
[49] xml2_1.3.2         prettyunits_1.1.1  assertthat_0.2.1   roxygen2_7.1.1     rstudioapi_0.11    R6_2.4.1           units_0.6-7        compiler_3.6.3 
  1. Answer to points 2 and 3

Yes, I fully agree with you: it makes no sense to reset GRASS several times with the same settings. It was just to show that the reset was going well and that as soon as link2GI::linkOTB() was called the GRASS initialization crashed right after.

  1. Answer to your last point

Yes, I agree with you and I already tried to link R and GRASS with link2GI::linkGRASS() but never succeeded (probably still linked to Windows 8.1). As an example, when I execute the simple command link2GI::findGRASS() here is the result :

> findGRASS(searchLocation = "C:")
NULL
Warning messages:
1: In system(paste0("cmd.exe /c TYPE \"", raw_GRASS[i], "\""), ignore.stdout = TRUE,  :
  running command 'cmd.exe /c TYPE "C:\Program Files\GRASS GIS 7.8\grass78.bat"' had status 1
2: In system(paste0("cmd.exe /c TYPE \"", raw_GRASS[i], "\""), ignore.stdout = TRUE,  :
  running command 'cmd.exe /c TYPE "C:\Program Files\QGIS 3.12\bin\grass78.bat"' had status 1
3: In system(paste0("cmd.exe /c TYPE \"", raw_GRASS[i], "\""), ignore.stdout = TRUE,  :
  running command 'cmd.exe /c TYPE "C:\Program Files\QGIS 3.12\etc\preremove\grass.bat"' had status 1

To conclude, I understand that all these problems (i.e. conflict between link2GI and rgrass7, problem in using the linkGI functions dedicated to link R and GRASS) are most probably related to Windows 8.1. For people using Windows 8.1 like me, you could, perhaps, put a warning message .

For my part I managed to fix the problem with a workaround. So, I'm not asking you to find a solution at all costs (I understand the difficulty of making all packages work perfectly in absolutely all working environments) and, therefore, you can close this thread if you wish.

Thanks again for your answer. Loïc

gisma commented 4 years ago

Dear Loïc, Sorry for this inconvenience. I will test your commands and some other checks asap under Windows 10. I'm not sure that the problems are caused by Windows 8.x and since I don't have Windows 8 available at the moment I can't test it. But from my bitter experience I can only recommend not to update Windows 8.1 to Windows 10 but to replace it with a new installation with Windows 10. If I can identify that the problems are caused by a special Windows version I will try to fix it or drop a warning. cheers Chris

gisma commented 4 years ago

Actually I am not able to reproduce the error and warning messages. However most of the stuff that happens is done with ASCII text manipulation which is strongly related to the code tables You use. Could you pls install a standalone GRASS version in a folder without any special character and whitespace in the path etc. and than re-check?I just want to make sure that the problem is not related to the special code table that you are using on your windows system.

lovalery commented 4 years ago

@gisma Dear Chris,

I'm sorry I couldn't do the test : I tried to install a second standalone version of GRASS but this is not possible because at the time of installation the first version is detected automatically and prevents the installation of the second version... and, to tell the truth, I don't really want to uninstall the first version that works : I'm afraid of doing something wrong ! (my standalone version of GRASS 7.8.3 is installed here : C:\Program Files\GRASS GIS 7.8)

Anyway, your hypothesis is probably good because when I made the link with OTB with link2GI::linkOTB(), I already had this space problem in the path. To make it work, I had to install OTB at the root (C:/OTB/) (because windows 8.1 automatically puts a space between Program and Files for its 'Program Files' directory). For OTB, this works fine, but it is not really recommended to install software directly at the root. It still remains preferable (and logical!) to install the softwares in the "Program Files" folder.

So , if you can fix this space problem (and if it's not too time-consuming !!), it would be very nice to do it, because I think it should work. Anyway, if you fix it, I will do the test immediately.

Kind regards Loïc