Skip to contents

Overview

rfp wraps the mergin-client CLI for pushing, sharing, and syncing QGIS projects with Mergin Maps. Field crews collect data on mobile devices via the Mergin Maps app; rfp handles the office-side workflow.

Authentication

The mergin CLI reads credentials from environment variables. Set in ~/.Renviron:

MERGIN_USERNAME=your_username
MERGIN_PASSWORD=your_password

Or use a bearer token (from mergin login):

MERGIN_AUTH=Bearer your_token_here

rfp checks for these before any Mergin operation and errors with actionable instructions if neither is set.

Create a project

After building a project with rfp_project_create(), push it to Mergin:

library(rfp)

rfp_mergin_create(
  "newgraph/sern_peace_2026",
  "~/Projects/gis/sern_peace_2026"
)
#> ℹ Creating Mergin project: newgraph/sern_peace_2026
#> ✔ Mergin project created: newgraph/sern_peace_2026

Share with collaborators

Grant access to field crew members:

rfp_mergin_share("newgraph/sern_peace_2026", "field_tech_1", "writer")
rfp_mergin_share("newgraph/sern_peace_2026", "field_tech_2", "writer")
rfp_mergin_share("newgraph/sern_peace_2026", "supervisor_1", "reader")

Permissions: "reader", "writer", or "owner".

Check sync status

See what’s changed locally and on the server:

rfp_mergin_status("~/Projects/gis/sern_peace_2026")
#> ### Server changes:
#> ### Local changes:
#> >>> Added:
#> + new_layer.gpkg
#> >>> Modified:
#> M form_pscis.gpkg

Sync

Pull server changes (field data) and push local changes (updated layers) until nothing local is left:

version <- rfp_mergin_sync("~/Projects/gis/sern_peace_2026")
#> ℹ Syncing Mergin project
#> ✔ Synced (version v43; 2 batches pushed)
cat("Synced to", version)

The Mergin client uploads at most 100 added and updated files per version, so a large change set lands as several versions, with a pull before each. rfp_mergin_sync() checks the outcome rather than trusting the client’s exit code, which is 0 even when a sync fails: no local changes may remain, the server must be at or above the local version, and the last version pushed must be the local one and be recorded under your login. Anything else is an error carrying the client’s output and log. Versions pulled between batches are reported, and a conflicted copy a pull created raises a warning.

Pull and push separately

For more control, call pull and push individually:

rfp_mergin_pull("~/Projects/gis/sern_peace_2026")
# ... review changes ...
version <- rfp_mergin_push("~/Projects/gis/sern_peace_2026")

rfp_mergin_push() uploads one version. With more than 100 changes pending it pushes the first batch, returns that version, and warns how many remain; rfp_mergin_sync() uploads the rest. A push the server did not record is an error, never a missing version.

Remove a project

Permanently delete a project from the Mergin server. Requires explicit confirmation to prevent accidental deletion:

rfp_mergin_remove("newgraph/test_project", confirm = TRUE)
#> ℹ Removing Mergin project: newgraph/test_project
#> ✔ Mergin project removed: newgraph/test_project

The local project directory is not touched.

Gotcha: close QGIS before syncing

When QGIS has a GeoPackage layer open, SQLite WAL mode creates sidecar files (*.gpkg-wal, *.gpkg-shm). These can cause conflicts during mergin pull or push because the diff engine can’t reconcile in-flight transactions.

Save and close the QGIS project before running rfp_mergin_sync().