Installing the qgisprocess Package
The qgisprocess package lets you run the algorithms that are in QGIS from an R session.
The main documentation is at R-Spatial and if you have installation problems then check there.
Installation – Simple Instructions
First, make sure you have QGIS and R installed. Then install the package in your usual package installation method, either by install.packages("qgisprocess") or using a menu item in your IDE.
install.packages("qgisprocess")That should be all you need if you have installed QGIS in a standard place.
Load the Package
Attach the package in the usual way from R. The first time you do this you should see something like this:
> library(qgisprocess)Attempting to load the package cache ... No cache found.
Will try to reconfigure qgisprocess and build new cache ...
QGIS version: 3.44.14-Solothurn
Having access to 739 algorithms from 9 QGIS processing providers.
Run `qgis_configure(use_cached_data = TRUE)` to reload cache and get more details.
>>> Run `qgis_enable_plugins()` to enable 2 disabled plugins and access
their algorithms: DataPlotly, Mergin
You may see a different number of algorithms and providers if you have a different version of QGIS or different plugins installed.
If this fails with an error like:
The 'qgis_process' command-line utility was either not found or
did not fulfil the needs to build the package cache.
then the package needs to know where your QGIS installation is, and you should look in the package documentation linked above for more details.
Run a QGIS Algorithm
Test running QGIS algorithms with the following three lines of code from an R session:
library(sf) # install the sf package if this is not found
nc = st_read(system.file("shape/nc.shp", package="sf"), quiet=TRUE)
qgis_run_algorithm("native:buffer", INPUT=nc, DISTANCE=0.1)which should produce something like:
Argument `SEGMENTS` is unspecified (using QGIS default value).
Using `END_CAP_STYLE = "Round"`
Using `JOIN_STYLE = "Round"`
Argument `MITER_LIMIT` is unspecified (using QGIS default value).
Argument `DISSOLVE` is unspecified (using QGIS default value).
Argument `SEPARATE_DISJOINT` is unspecified (using QGIS default value).
Using `OUTPUT = qgis_tmp_vector()`
Using non-preferred coordinate operation between EPSG:4267 and EPSG:4326. Using +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-10 +y=158 +z=187 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg, preferred +proj=pipeline +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=ca_nrc_ntv2_0.tif +step +proj=unitconvert +xy_in=rad +xy_out=deg.
<Result of `qgis_run_algorithm("native:buffer", ...)`>
List of 1
$ OUTPUT: 'qgis_outputVector' chr "/tmp/RtmpVfxKUf/file19e58e68970264/file19e58e64979b3a.gpkg"
Success
This final line with an OUTPUT reference shows that it has all worked. You can now try the Site Suitability worksheet that goes through the package in more detail.
If this doesn’t work, check with the documentation above or ask an expert.