Skip to contents

A project stores its background layers either as one GeoPackage per layer under background_layers/ or as a single background_layers.gpkg - see rfp-layout. This is the single place that resolution happens, and it is exported so a consumer outside rfp reads a project the way rfp does instead of hardcoding one of the two shapes.

Usage

rfp_layout(
  path,
  dir_layers = NULL,
  file_gpkg = NULL,
  layout = NULL,
  fn_layer_file = NULL
)

Arguments

path

Character. Project directory.

dir_layers

Character. Directory holding per-layer GeoPackages. NULL (default) resolves getOption("rfp.dir_layers").

file_gpkg

Character. Single-GeoPackage file name. NULL (default) resolves getOption("rfp.file_gpkg").

layout

Character. "split", "monolith", or NULL (default) to detect from disk. An explicit value skips detection entirely, which is what project creation needs - nothing exists yet to detect.

fn_layer_file

Function mapping a layer name to its file name under the split layout. NULL (default) resolves getOption("rfp.fn_layer_file").

Value

A list - the layout spec - with kind ("split"/"monolith"), path, dir_layers, file_gpkg, dir (layers directory, split), gpkg (single file, monolith) and fn_layer_file. Pass it to rfp_layout_layers() and rfp_layout_layer_path().

Details

Three things a reimplementation gets wrong, which is why this is shared rather than copied. Every name resolves argument, then session option, then package default. With layout = NULL the layout is read from disk, and a project holding both warns and resolves to the directory rather than silently picking one - the mid-migration case. And fn_layer_file is a function, so <schema>.<table>.gpkg stays a convention rather than a rule.

Examples

project <- file.path(tempdir(), "layout_example")
dir.create(project)

# Nothing on disk falls back to the historical single-GeoPackage layout, so
# a caller keeps producing its existing "no GeoPackage here" error.
rfp_layout(project)$kind
#> [1] "monolith"

dir.create(file.path(project, "background_layers"))
spec <- rfp_layout(project)
spec$kind
#> [1] "split"
spec$dir
#> /tmp/RtmpfSNDuG/layout_example/background_layers

unlink(project, recursive = TRUE)