TransWikia.com

QGIS enabling R via plugin

Geographic Information Systems Asked on February 1, 2021

System Ubuntu 19.10, QGIS 3.4

I am trying to utilise R in QGIS for Ripley’s K function.

The sample R script ‘Scatterplot’ works with the Processing R Provider plugin, which indicates r-base is installed OK. However, I have installed the Spatstat package and the various categories do not appear in the QGIS Processing Toolbox.

I am guessing the R scripts folder needs setting? If so, what would I need to direct the plugin to?

2 Answers

This is my settings.

  1. The location R is installed.
  2. R scripts folder is accessed from Menu > Settings > User Profiles > Open Active Profile Folder.
  3. User library folder is where I have R packages.

enter image description here

Then, RSX script for Ripley's K:

enter image description here

##Kazuhito Vector Analysis=group
##Layer=vector point
##showplots
library("maptools")
library("spatstat")
points=as.ppp(Layer)
K=Kest(points)
plot(K)

It gives me this html output (via Results Viewer panel):

enter image description here

File system would be different from yours, but hope this helps.

Answered by Kazuhito on February 1, 2021

Edit

Version 0.9.0 of the Resource Sharing plugin was made available on http://plugins.qgis.org today (https://plugins.qgis.org/plugins/qgis_resource_sharing), and the good news is that it includes support for R script collections. See https://gis.stackexchange.com/a/341008/22646 for more details, and for information about available collections and repositories.

The QGIS Official Repository now also includes a collection with R scripts. The name of the collection is QGIS R script collection.

Original answer

(modified according to recent developments in the official QGIS repository)

It is currently not possible to "import" R scripts from the on-line collection (as could be done in QGIS 2), but it is possible to download the scripts and add them "manually". See https://gis.stackexchange.com/a/341008/22646.

The "QGIS Resource Sharing" plugin supports import of R script collections. I have done some testing by creating a resource for the plugin that contains these QGIS 2 R scripts.

Using the following steps, I was able to get this to work in QGIS 3.10.1 (I suppose it should work also with QGIS 3.4).

  1. Add the "QGIS Resource Sharing" plugin
  2. Open it (Plugins-> Resource Sharing-> Resource Sharing)
  3. Choose the Settings tab
  4. Click Reload repositories
  5. Choose the All tab
  6. Select QGIS R script collection in the list to install R scripts that work in QGIS 3 with Processing R provider 2 (select QGIS R script collection (from QGIS 2) if you want the original QGIS 2 collection - many of these scripts need to be modified to work), click on the Install button
  7. The collection should now be listed in the Install tab
  8. Close the plugin

With recent versions (>= 0.9.0) of the QGIS Resource Sharing plugin the R scripts should now be available under various groups under R in the processing toolbar (see illustration below).

With older versions (< 0.9.0) of the plugin, you also have to:

  1. Open the Processing settings (Settings-> Options-> Processing tab)

  2. Go to Providers-> R-> R scripts folder

  3. On Ubuntu, set the path to (or include in the path):

    /home/<user>/.local/share/QGIS/QGIS3/profiles/default/resource_sharing/repositories/github.com/havatv/qgis_rscripts/collections/R-scripts-QGIS2/processing/rscriptsqgis2

    On Windows, set the path to:

    C:Users<user>AppDataRoamingQGISQGIS3profilesdefaultresource_sharingrepositoriesgithub.comhavatvqgis_rscriptscollectionsR-scripts-QGIS2processingrscriptsqgis2

    It is possible to provide several directories here, separated by a semicolon (";").

  4. All the R scrips from the QGIS 2 on-line collection should now be available in the Processing Toolbox (only some of the groups are expanded in the screenshot below):

    Processing toolbox with some R scripts shown

    The scripts at the top come from the default rscripts folder - it is included in my R scripts folder path.

Answered by Håvard Tveite on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP