Skip to contents

Provisions a project-local Python environment via pyro (writing a quartifyr dependency group to the calling project's pyproject.toml) so render_report()'s styling_*() calls have a quartifyr_styling venv to run against. Call this once per report project, alongside reportifyr::initialize_report_project() – not implied by render_report() itself, since re-provisioning on every render would be wasteful.

Usage

initialize_quartifyr_project(
  directory = ".",
  from_dir = NULL,
  from_repo = NULL,
  ref = NULL,
  subdir = NULL,
  type = NULL,
  force = FALSE,
  python_env = getOption("quartifyr.python_env"),
  install_extensions = FALSE,
  extensions_from = NULL
)

Arguments

directory

Target project directory. Defaults to the current directory.

from_dir

Use a local directory as the template source instead of leaving directory empty. Mutually exclusive with from_repo.

from_repo

Fetch a git repo as the template source: "[host/]owner/repo[/subdir][@ref]" shorthand (host defaults to github.com – an explicit host is how GitHub Enterprise is supported) or a full URL. Requires git on PATH. Mutually exclusive with from_dir.

ref

Branch/tag/SHA to check out. Only valid with from_repo; overrides any @ref embedded in its shorthand.

subdir

Subdirectory of the resolved repo to use as the template source. Only valid with from_repo; overrides any subdirectory embedded in its shorthand.

type

Template name under a source's templates/<name>/ structure. Only valid alongside from_dir/from_repo.

force

Overwrite existing _quarto.yml/style YAML/shell .qmd files in directory. Only meaningful alongside from_dir/from_repo. Default FALSE.

python_env

Path to an existing Python environment (a venv, or a project directory holding a .venv) that already has python-docx and pyyaml. It is checked (naming any missing module; quartifyr_styling itself comes from the copy bundled in this package) and then pyro and uv are skipped entirely: nothing is written to pyproject.toml and no environment is created. Defaults to getOption("quartifyr.python_env"). For the styling_*() calls in render_report() to use it too, set that option (or the QUARTIFYR_PYTHON_ENV environment variable) in the project's .Rprofile. With it set, render_report() also runs reportifyr's pass 2 in that environment (which then needs pillow too), so the project needs no .venv; set up the report folders and marker without pyro or the network with initialize_report_project_offline().

install_extensions

Also install the Quarto extensions the project needs: quarto-plus via install_quarto_extensions() (from extensions_from, default the copy bundled in this package) and quartifyr's own via install_quartifyr_extension(), unless already present. Neither touches the network. Default FALSE.

extensions_from

Passed as from to install_quarto_extensions(). Only used with install_extensions = TRUE.

Value

Invisibly, the result of pyro::initialize_python() (NULL when python_env is used).

Details

When from_dir/from_repo is given (issue #23), also scaffolds directory's _quarto.yml/style YAML/shell .qmd from a template source instead of leaving directory empty: either a local directory (from_dir) or a git repo (from_repo), fetched and materialized the same way ../deckifyr's initialize_deck_project() does for its own design.yaml/layouts.yaml/presentation.yaml. A template source is either "flat" (a directory with its own _quarto.yml and exactly one .qmd file at its root – its _quarto.yml/style.yaml, if present, are duplicated as-is, paired with a freshly generated, minimal shell .qmd) or "typed" (a directory with a templates/ subdirectory, each holding its own named flat template – select one with type; its shell .qmd is copied verbatim as a real minimal starter, not emptied).

A stale-venv gotcha in existing reportifyr projects

On a project already initialized by reportifyr before it depended on pyro (reportifyr < 0.4.0), this can fail with an opaque error from pyro::initialize_python()'s underlying uv sync call – that project's Python environment predates pyro/uv and isn't necessarily something uv can adopt as-is. Run reportifyr::initialize_report_project(project_dir = directory) first (safe to re-run) to bring the environment up to a pyro-compatible state before calling this function. This function catches that failure and re-raises with a pointer to the same fix, instead of letting pyro/uv's raw error propagate uninterpreted.

Offline use

Nothing here needs the network if what it would download is already local; see the "Offline use" article on the package website for the whole recipe. Offline mode is on when options(quartifyr.offline = TRUE) or uv's own UV_OFFLINE=1 is set. In it:

  • pyro's provisioning runs with UV_OFFLINE=1, so uv lock/uv sync resolve from uv's cache or UV_FIND_LINKS wheels instead of PyPI;

  • if uv isn't installed it stops with a message saying so, rather than letting pyro download and install uv from GitHub (into ~/.local/bin);

  • from_repo is refused (clone the repository yourself and use from_dir);

  • a failure that needed the network says which step, which resource, and how to provide it locally (error class quartifyr_offline_failure).

Alternatively, python_env skips pyro and uv altogether.

Examples

if (FALSE) { # \dontrun{
# Provision the Python environment only (this mutates the calling
# project's pyproject.toml and provisions a Python/uv environment --
# run it somewhere disposable, not the current project).
project_dir <- file.path(tempdir(), "my-report")
initialize_quartifyr_project(project_dir)

# Also scaffold _quarto.yml/style.yaml/report.qmd from an org-standard
# template repo, pinned to a tag, selecting the "csr" template type.
initialize_quartifyr_project(
  project_dir,
  from_repo = "acme-org/quartifyr-templates@v2",
  type = "csr"
)
} # }