Easy Spatial Modeling with Random Forest
Overview
Automatic generation and selection of spatial predictors for Random Forest models fitted to spatially structured data. Spatial predictors are constructed from a distance matrix among training samples using Moran's Eigenvector Maps (MEMs; Dray, Legendre, and Peres-Neto 2006 DOI:10.1016/j.ecolmodel.2006.02.015) or the RFsp approach (Hengl et al. DOI:10.7717/peerj.5518). These predictors are used alongside user-supplied explanatory variables in Random Forest models. The package provides functions for model fitting, multicollinearity reduction, interaction identification, hyperparameter tuning, evaluation via spatial cross-validation, and result visualization using partial dependence and interaction plots. Model fitting relies on the 'ranger' package (Wright and Ziegler 2017 DOI:10.18637/jss.v077.i01).
- Fixed Windows-specific error in
get_response_curves(),plot_response_curves(),rf_evaluate(), andrf()wherepredict()method dispatch failed to findpredict.ranger(). Added@importFrom ranger rangerto ensure ranger's namespace is loaded and S3 methods are properly registered. - Code quality improvements: fixed 129 linting issues identified by jarl linter, including inefficient vector logic operators in if statements (
|→||,&→&&), redundant equality comparisons (== TRUE→ direct boolean), and corrected two bugs inon.exit()calls that weren't properly restoring user options. - Fixed error
Error in validate_prop(value, prop, check_fun, check_values, reset_na) : check_fun(value) is not TRUEgenerated byhuxtable::set_all_borders(TRUE). - Fixed warning "Using
sizeaesthetic for lines was deprecated in ggplot2 3.4.0. ℹ Please uselinewidthinstead." produced by outdated calls togeom_line(). - Fixed issue with deprecated argument
draw_quantilesofgeom_violin(). - Replaced deprecated calls to
ggplot2::aes_string()withggplot2::aes()plus.data[[whatever]]. - Fixed parallelization issues with zombi processess across functions.
- Added internal helper function
setup_parallel_execution()to centralize and improve parallel backend management across all functions. Now properly detects and respects user-configured backends (viafuture,doParallel, etc.) while maintaining support for external and internal cluster objects. - Refactored cluster setup code across all parallelized functions (
rf_spatial(),rf_evaluate(),rf_tuning(),rf_repeat(),rf_compare(),rf_importance(),the_feature_engineer(),select_spatial_predictors_sequential(),select_spatial_predictors_recursive()) to use the new helper, improving consistency and reducing code duplication. - Removed
if(interactive()){}wrappers from function examples to ensure examples run during R CMD check. - Function
rf_spatial()now fits a spatial model even when that's not necessary. - Simplified
auto_cor()andauto_vif()with unified sequential evaluation algorithm that better preserves user preference order.
From NEWS.md in the release
Install
Health
- OK13 OK2026-09-18
- WARNING12 OK, 1 WARNING2026-09-12
- OK13 OK2026-08-04
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
Show 3 earlier changesHide 3 earlier changes
- ERROR12 OK, 1 ERROR2026-06-08
- OK12 OK2026-04-25
- NOTE11 OK, 3 NOTE2026-03-10
Documentation
The repository also keeps web-only articles.
- Help pages
- 74 (1 internal)
- Examples that run
- 97%62 run in a plain check (14 of them under a condition) · 2 never run
- Exported functions with examples
- 95%
- Documented parameters
- 94%
- Return-value docs
- 100%
- Help pages citing references
- 0%
Downloads
Repository
- PRs merged (all time)
- 0%
- Median days to close, 50 most recently updated closed issues
- 38
- Median days to close, 50 most recently updated closed PRs
- 2
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
Commits over time
8 development-tooling and community-health practices detected across 4 families in the upstream repository
Checks run against github.com/blasbenito/spatialrf on 2026-10-18.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-07-15 · The repository has a site deploy workflow
pkgdown site last built 2026-07-15
Dependencies
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- RR 4.6.0 released · 2026-04-24
- 1.1.5Latest2025-12-20 · current release · diff ↗ ·
removed 3 exports
.select_by_max_vif, .select_by_preference, vifadded 2 exports
%>%, setup_parallel_execution - RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- RR 4.3.0 released · 2023-04-21
- 1.1.42022-08-19 · diff ↗
- RR 4.2.0 released · 2022-04-22
- 1.1.32021-09-23
- RR 4.1.0 released · 2021-05-18
Package metadata
- First published
- 2021-09-23
- Total releases
- 3 / 5 yrs
- License
- MIT + file LICENSE OSI · relicensed from GPL-3 in 1.1.5
- Minimum R
- ≥ 2.10
- Bundled data
- 942 KB / 7 files
- Download size
- 3.4 MB
Cite
Cite this package
Run in R for the authors' entry:
citation("spatialRF")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.18637/jss.v077.i01, 10.5281/zenodo.4745208.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-21, which the citation names so these numbers can be found later. More on citing and the projects behind them.