3

I want to use GRASS in Rstudio to crop my DEM with my GRASS region definited. I tried to install r.clipextension on GRASS with g.extension to realise this. But when I use the function g.extension to import r.clip in GRASS I have error ERREUR : Variable 'LOCATION_NAME' non définie. My code is :

install.packages("rgrass7")
library(rgrass7)

# Creation Grass environment 
initGRASS("C:/Program Files/GRASS GIS 7.6",
          override = TRUE,
          gisDbase = "GRASS_TEMP",
          home = tempdir(),
          mapset = "PERMANENT",
          remove_GISRC = TRUE)

# To install extension 
execGRASS(cmd = "g.extension",
          flags = "s",
          parameters = list(extension = "r.clip", operation = "add"))

And the code to install extension return this error :

> execGRASS(cmd = "g.extension",
+           flags = "s",
+           parameters = list(extension = "r.clip", operation = "add"))

ATTENTION: Extension <r.clip> already installed. Re-installing...
Downloading precompiled GRASS Addons <r.clip>...
ERREUR :Variable 'LOCATION_NAME' non définie
ERREUR :Variable 'LOCATION_NAME' non définie
ERREUR :Variable 'LOCATION_NAME' non définie
Traceback (most recent call last):
  File "C:/Program Files/GRASS GIS 7.6/scripts/g.extension.py", line 1748, in <module>
    sys.exit(main())
  File "C:/Program Files/GRASS GIS 7.6/scripts/g.extension.py", line 1727, in main
    install_extension(source=source, url=url, xmlurl=xmlurl)
  File "C:/Program Files/GRASS GIS 7.6/scripts/g.extension.py", line 702, in install_extension
    blist = install_extension_xml(xmlurl, mlist)
  File "C:/Program Files/GRASS GIS 7.6/scripts/g.extension.py", line 922, in install_extension_xml
    write_xml_modules(xml_file, tree)
  File "C:/Program Files/GRASS GIS 7.6/scripts/g.extension.py", line 601, in write_xml_modules
    libgis_revison = grass.version()['libgis_revision']
KeyError: 'libgis_revision'

> execGRASS(cmd = "r.clip",
+           flags = "overwrite",
+           parameters = list (input = "GRASS_MNS",
+                              output = "GRASS_MNT_crop"))

Error : XML content does not seem to be XML: ' No such file or directory'
De plus : Warning message:
In system(cmd0, intern = TRUE) :
  l'exécution de la commande 'r.clip.bat --interface-description' renvoie un statut 2
Error in parseGRASS(cmd, legacyExec = legacyExec) : r.clip not parsed

When I check the manuel of the g.extension function, I saw that -s argument in flags can to be use but the system administrator rights are necessary. So I have given the right at my folder where GRASS 7.6 is installed and I'm administrator of my computer.

When I install r.clip in Grass interface, installation is successfully finished but it's impossible to find r.clip extension in extension list of Grass.

enter image description here

enter image description here

But when I research r.clip extension in Rstudio with code below, I find it !

> execGRASS(cmd = "g.extension",
+           flags = "l")

ATTENTION: GRASS_ADDON_BASE is not defined, installing to ~/.grass7/addons
List of available extensions (modules):
r.clip
...

I use GRASS 7.6.1 installed in C:/Program Files/GRASS GIS 7.6 and R 3.6.1.

1 Answer 1

2

GRASS extensions should be manually downloaded and installed on MS Windows.

Now r.clip should work.

2
  • I don't have "addons" file, I must create this file and unzip r.clip into it ? In "GRASS7" I have only "toolboxes" file empty.
    – Romain
    Commented May 13, 2020 at 6:48
  • 1
    Yes, you have to create the "addons" directory manually if needed.
    – bonzinor
    Commented May 15, 2020 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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