Skip to contents

Make the first local copy of a Mergin Maps project. Wraps mergin download from the mergin-client CLI (see rfp_mergin_bin()). rfp_mergin_pull() updates a copy that already exists; this makes the one it updates.

Usage

rfp_mergin_download(project, path, version = NULL)

Arguments

project

Character. Full Mergin project name as namespace/project (e.g., "newgraph/hornby_2026").

path

Character. Directory to download into. Must not exist yet.

version

Character. "vN" to download the project as it stood at that version, or NULL (default) for the current HEAD. A version the project does not have is refused before anything is downloaded.

Value

Invisible character - path, absolute.

Details

The download is pinned to one version: version if given, otherwise the one the server reports when the call starts, so a project that receives field data while it downloads still yields a copy of one definite version. The next rfp_mergin_pull() brings the copy up to the current HEAD.

The CLI exits 0 when a download fails - it catches its own errors and prints them - so the exit status is not the verdict. The copy is checked instead, with no further server call: .mergin/mergin.json must exist and carry the pinned version (the CLI writes it last), and every file it lists must be on disk at its listed size. A .gpkg/.sqlite is checked for presence only: upstream size-checks those itself when the version is still the latest, and skips them otherwise because the server may rebuild an older one on demand.

path must not exist, not even as an empty directory. The CLI downloads into a private staging directory this call creates beside path (mode 0700, claimed atomically), and the verified copy is renamed to path. A failed download is removed, because the CLI leaves its partial directory behind; only the staging directory this call created is ever deleted, and never through a symlink. An interrupt (Esc, Ctrl-C) deletes nothing, since the CLI may still be writing. A non-zero exit with a complete copy keeps the copy and warns. If path appears while the download runs, the verified copy is left in the staging directory and the error names it.

Nothing is printed while the CLI runs, which for a large project is minutes. Chunks are staged in the system temp directory, so the transfer needs about the project's size free there as well as at path.

Authentication is the same as rfp_mergin_create(): MERGIN_USERNAME + MERGIN_PASSWORD, or MERGIN_AUTH.

Examples

if (FALSE) { # \dontrun{
rfp_mergin_download("newgraph/hornby_2026", "~/Projects/gis/hornby_2026")

# The project as it stood at a pinned version
rfp_mergin_download("newgraph/hornby_2026", "~/Projects/gis/hornby_v10",
                    version = "v10")

# Later updates go through pull
rfp_mergin_pull("~/Projects/gis/hornby_2026")
} # }