| Title: | Document Intelligence via 'Docling' |
|---|---|
| Description: | An interface to 'Docling', a document-understanding library that converts 'PDF', 'DOCX', 'PPTX', 'HTML' and image documents into structured, AI-ready data. The package wraps the 'Docling' 'Python' package through 'reticulate' to extract layout-aware text, tables and metadata, export to 'Markdown' or 'JSON', and split documents into context-rich chunks suitable for retrieval-augmented generation (RAG) and embedding pipelines. |
| Authors: | Andre Leite [aut, cre], Marcos Wasilew [aut], Hugo Vasconcelos [aut], Carlos Amorim [aut], Diogo Bezerra [aut] |
| Maintainer: | Andre Leite <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-10 22:48:03 UTC |
| Source: | https://github.com/cran/doclingr |
Checks whether the docling Python package can be imported in the active
'reticulate' environment.
docling_available()docling_available()
A logical scalar.
## Not run: docling_available() ## End(Not run)## Not run: docling_available() ## End(Not run)
Apply a Docling chunker to a converted document and return the chunks as a
tidy tibble. The default "hybrid" chunker produces tokenization-aware,
context-enriched chunks well suited to embedding and retrieval pipelines; the
"hierarchical" chunker follows the document's structural hierarchy without
a token budget.
docling_chunk( x, chunker = c("hybrid", "hierarchical"), tokenizer = NULL, max_tokens = NULL, contextualize = TRUE, ... )docling_chunk( x, chunker = c("hybrid", "hierarchical"), tokenizer = NULL, max_tokens = NULL, contextualize = TRUE, ... )
x |
A |
chunker |
Either |
tokenizer |
Hugging Face model id whose tokenizer is used to count
tokens (hybrid chunker only). Defaults to a small sentence-embedding
tokenizer when |
max_tokens |
Optional integer token budget per chunk (hybrid chunker
only). When |
contextualize |
When |
... |
Additional keyword arguments forwarded to the Python chunker
constructor (for example |
The hybrid chunker is token-aware: it packs content up to a token budget and
splits oversized passages. Control this with tokenizer (the model whose
tokenizer defines "a token") and max_tokens (the budget). These are ignored
by the hierarchical chunker.
A tibble::tibble with one row per chunk and columns:
chunk_id — 1-based index.
text — contextualized text (or raw text if contextualize = FALSE).
raw_text — the chunk's unmodified text.
n_chars — number of characters in text.
headings — list-column of heading paths for the chunk.
pages — list-column of integer page numbers the chunk spans.
n_doc_items — number of underlying document items in the chunk.
docling_convert(), docling_embed()
## Not run: doc <- docling_convert("paper.pdf") chunks <- docling_chunk(doc, max_tokens = 512) chunks$text[1] # Match your embedding model's tokenizer docling_chunk(doc, tokenizer = "BAAI/bge-small-en-v1.5", max_tokens = 512) ## End(Not run)## Not run: doc <- docling_convert("paper.pdf") chunks <- docling_chunk(doc, max_tokens = 512) chunks$text[1] # Match your embedding model's tokenizer docling_chunk(doc, tokenizer = "BAAI/bge-small-en-v1.5", max_tokens = 512) ## End(Not run)
Runs Docling's document-understanding pipeline over local file paths or URLs
and returns lightweight R handles around the resulting DoclingDocuments.
Each handle can be exported to Markdown or JSON (as_markdown(),
as_json()), mined for tables (docling_tables()), or split into chunks
for RAG (docling_chunk()).
docling_convert( source, ocr = TRUE, table_mode = c("accurate", "fast"), device = c("auto", "cpu", "cuda", "mps"), num_threads = NULL, images = FALSE, images_scale = 1, ... )docling_convert( source, ocr = TRUE, table_mode = c("accurate", "fast"), device = c("auto", "cpu", "cuda", "mps"), num_threads = NULL, images = FALSE, images_scale = 1, ... )
source |
A character vector of file paths and/or URLs. A single source
returns one |
ocr |
Logical; run OCR on the document. Defaults to |
table_mode |
Table-structure model mode, one of |
device |
Accelerator device for the deep-learning models: |
num_threads |
Optional integer number of CPU threads for the
accelerator. |
images |
Logical; generate and retain page and picture images so they
can be saved later with |
images_scale |
Image resolution scale relative to 72 DPI when |
... |
Reserved for future pipeline options; currently ignored with a warning if supplied. |
Supported inputs include PDF, DOCX, PPTX, XLSX, HTML, Markdown, AsciiDoc and common image formats, as determined by the installed Docling version.
For a single source, an object of class docling_document (a list
with the underlying Python document and the original source). For
multiple sources, a docling_document_list: a list of docling_document
objects named by source.
as_markdown(), docling_tables(), docling_chunk()
## Not run: doc <- docling_convert("https://arxiv.org/pdf/2408.09869") as_markdown(doc) # Batch, OCR off, fast tables docs <- docling_convert(c("a.pdf", "b.pdf"), ocr = FALSE, table_mode = "fast") ## End(Not run)## Not run: doc <- docling_convert("https://arxiv.org/pdf/2408.09869") as_markdown(doc) # Batch, OCR off, fast tables docs <- docling_convert(c("a.pdf", "b.pdf"), ocr = FALSE, table_mode = "fast") ## End(Not run)
Embed a chunk tibble's text with a user-supplied embedding function and
return the tibble with an embedding list-column. doclingr stays
provider-agnostic: you bring the embedder (an OpenAI/Cohere/Ollama API
call, a local sentence-transformers model via reticulate, anything), and this
helper handles batching, validation and tidy assembly.
docling_embed(chunks, embedder, text_column = "text", batch_size = NULL)docling_embed(chunks, embedder, text_column = "text", batch_size = NULL)
chunks |
A tibble of chunks, typically from |
embedder |
A function taking a character vector and returning either a numeric matrix with one row per input, or a list of equal-length numeric vectors. |
text_column |
Name of the column to embed. Defaults to |
batch_size |
Optional integer; if set, |
chunks with an added embedding list-column of numeric vectors,
and an n_dim integer column giving each embedding's length.
## Not run: chunks <- docling_chunk(docling_convert("paper.pdf"), max_tokens = 512) # Any embedder: here a toy one embed_fn <- function(txt) matrix(stats::runif(length(txt) * 8), nrow = length(txt)) docling_embed(chunks, embed_fn) ## End(Not run)## Not run: chunks <- docling_chunk(docling_convert("paper.pdf"), max_tokens = 512) # Any embedder: here a toy one embed_fn <- function(txt) matrix(stats::runif(length(txt) * 8), nrow = length(txt)) docling_embed(chunks, embed_fn) ## End(Not run)
Render a docling_convert() result into a downstream-friendly format.
as_markdown(x, ...) ## S3 method for class 'docling_document' as_markdown(x, ...) as_text(x, ...) ## S3 method for class 'docling_document' as_text(x, ...) as_html(x, ...) ## S3 method for class 'docling_document' as_html(x, ...) as_json(x, ...) ## S3 method for class 'docling_document' as_json(x, ...) as_doctags(x, ...) ## S3 method for class 'docling_document' as_doctags(x, ...)as_markdown(x, ...) ## S3 method for class 'docling_document' as_markdown(x, ...) as_text(x, ...) ## S3 method for class 'docling_document' as_text(x, ...) as_html(x, ...) ## S3 method for class 'docling_document' as_html(x, ...) as_json(x, ...) ## S3 method for class 'docling_document' as_json(x, ...) as_doctags(x, ...) ## S3 method for class 'docling_document' as_doctags(x, ...)
x |
A |
... |
Additional arguments passed to the underlying Docling export
method (for example |
as_markdown(): a length-1 character string of Markdown.
as_text(): a length-1 character string of plain text.
as_html(): a length-1 character string of HTML.
as_json(): an R list mirroring the DoclingDocument structure.
as_doctags(): a length-1 character string in Docling's DocTags format.
## Not run: doc <- docling_convert("report.pdf") as_markdown(doc) str(as_json(doc), max.level = 1) ## End(Not run)## Not run: doc <- docling_convert("report.pdf") as_markdown(doc) str(as_json(doc), max.level = 1) ## End(Not run)
Return a tidy tibble of the pictures Docling detected, with their captions
and page numbers. When image_dir is supplied and the document was converted
with images = TRUE, each picture is written to disk and its path returned.
docling_figures(x, image_dir = NULL, format = "png")docling_figures(x, image_dir = NULL, format = "png")
x |
A |
image_dir |
Optional directory to save picture images into. Created if
it does not exist. Requires |
format |
Image file format when saving, for example |
A tibble::tibble with one row per figure and columns:
figure_id — 1-based index.
caption — caption text (empty string if none).
page — page number the figure appears on (NA if unknown).
image_path — path to the saved image, or NA if not saved.
## Not run: doc <- docling_convert("paper.pdf", images = TRUE) figs <- docling_figures(doc, image_dir = "figures") figs$image_path ## End(Not run)## Not run: doc <- docling_convert("paper.pdf", images = TRUE) figs <- docling_figures(doc, image_dir = "figures") figs$image_path ## End(Not run)
Number of pages in a converted document
docling_n_pages(x)docling_n_pages(x)
x |
A |
An integer page count (0 for page-less formats such as Markdown).
## Not run: docling_n_pages(docling_convert("report.pdf")) ## End(Not run)## Not run: docling_n_pages(docling_convert("report.pdf")) ## End(Not run)
Pull every table detected by Docling out of a converted document and return them as a list of tibbles, preserving the document order.
docling_tables(x)docling_tables(x)
x |
A |
A list of tibble::tibbles, one per detected table. The list is
empty if no tables were found. Each element carries a page attribute when
Docling reports the originating page.
## Not run: doc <- docling_convert("financials.pdf") tbls <- docling_tables(doc) tbls[[1]] ## End(Not run)## Not run: doc <- docling_convert("financials.pdf") tbls <- docling_tables(doc) tbls[[1]] ## End(Not run)
Installs the docling Python package (and its dependencies) into a
'reticulate'-managed environment. This is a thin wrapper around
reticulate::py_install() that you typically run once after installing
doclingr.
install_docling( envname = "r-docling", method = c("auto", "virtualenv", "conda"), extra = NULL, ... )install_docling( envname = "r-docling", method = c("auto", "virtualenv", "conda"), extra = NULL, ... )
envname |
Name of, or path to, the target Python environment. Defaults
to |
method |
Installation method passed to |
extra |
Optional character vector of additional pip/conda specs to
install alongside Docling (for example |
... |
Further arguments forwarded to |
Invisibly NULL, called for its side effect.
docling_available(), docling_convert()