| Title: | Read Paradox Database Files into R |
|---|---|
| Description: | Provides a simple and efficient way to read data from Paradox database files (.db) directly into R as modern 'tibble' data frames. It uses the underlying 'pxlib' C library, to handle the low-level file format details and provides a clean, user-friendly R interface. |
| Authors: | Daniil Popov [aut, cre] |
| Maintainer: | Daniil Popov <[email protected]> |
| License: | GPL(>=2) |
| Version: | 0.2.2 |
| Built: | 2026-05-17 08:07:20 UTC |
| Source: | https://github.com/celebithil/rparadox |
This function explicitly closes a Paradox database file associated with
a pxdoc_t external pointer and releases its resources.
pxlib_close_file(pxdoc)pxlib_close_file(pxdoc)
pxdoc |
An external pointer of class 'pxdoc_t' obtained from |
Invisible NULL.
Retrieves all records from an open Paradox database file and returns them as a tibble, ready for use in R.
pxlib_get_data(pxdoc)pxlib_get_data(pxdoc)
pxdoc |
An object of class |
This function provides a high-level interface for reading Paradox data.
The heavy lifting is done by a C-level function (R_pxlib_get_data) which
efficiently reads the raw data into memory. This R function then acts as a
wrapper to perform crucial post-processing steps:
It identifies columns containing binary (BLOB) data and correctly
converts them into blob objects.
It ensures that date/time columns are properly classed for seamless integration with other R functions.
The result is a clean, modern tibble that is fully compatible with the
tidyverse ecosystem.
A tibble containing the data from the Paradox file. Each row
represents a record and each column represents a field. If the file contains
no records, an empty tibble is returned.
# Define the path to the demo database included with the package db_path <- system.file("extdata", "biolife.db", package = "Rparadox") # Open the file handle pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { # Read all data into a tibble biolife_data <- pxlib_get_data(pxdoc) # Always close the file handle when finished pxlib_close_file(pxdoc) # Work with the data print(biolife_data) }# Define the path to the demo database included with the package db_path <- system.file("extdata", "biolife.db", package = "Rparadox") # Open the file handle pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { # Read all data into a tibble biolife_data <- pxlib_get_data(pxdoc) # Always close the file handle when finished pxlib_close_file(pxdoc) # Work with the data print(biolife_data) }
Retrieves metadata from an open Paradox file handle without reading the entire dataset.
pxlib_metadata(pxdoc)pxlib_metadata(pxdoc)
pxdoc |
An object of class |
A list containing:
num_records |
The total number of records in the database. |
num_fields |
The total number of fields (columns). |
encoding |
The character encoding specified in the file header (e.g., "CP1251"). |
fields |
A data frame with details for each field, with names recoded to UTF-8. |
db_path <- system.file("extdata", "country.db", package = "Rparadox") pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { metadata <- pxlib_metadata(pxdoc) print(metadata) pxlib_close_file(pxdoc) }db_path <- system.file("extdata", "country.db", package = "Rparadox") pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { metadata <- pxlib_metadata(pxdoc) print(metadata) pxlib_close_file(pxdoc) }
Opens a Paradox database (.db) file and prepares it for reading. This function serves as the entry point for interacting with a Paradox database.
pxlib_open_file(path, encoding = NULL, password = NULL)pxlib_open_file(path, encoding = NULL, password = NULL)
path |
A character string specifying the path to the Paradox (.db) file. |
encoding |
An optional character string specifying the source encoding
(e.g., "cp866", "cp1252"). If |
password |
An optional character string specifying the password for
encrypted files. If the file is encrypted and no password is provided,
an error will be thrown. Default is |
This function initializes a connection to a Paradox file via the underlying C library. It automatically performs two key setup tasks:
Encoding Override: It allows the user to specify the character encoding of the
source file via the encoding parameter. This is crucial for legacy files
where the encoding stored in the header may be incorrect. If encoding is
NULL, the function will attempt to use the codepage from the file header.
BLOB File Attachment: It automatically searches for an associated BLOB file
(with a .mb extension, case-insensitively) in the same directory and,
if found, attaches it to the database handle.
This function automatically handles encrypted Paradox files:
If the file is not encrypted, the password parameter is ignored
If the file is encrypted and password is provided, it validates the password
If the file is encrypted and password is NULL, an error is thrown
If the provided password is incorrect, an error is thrown
When a file is successfully opened with the correct password, all subsequent
operations (like pxlib_get_data()) will automatically decrypt the data.
It's important to always close the file handle using pxlib_close_file()
when you're done to prevent resource leaks. Using on.exit() is recommended:
px_doc <- pxlib_open_file("myfile.db", password = "secret")
on.exit(pxlib_close_file(px_doc), add = TRUE)
# ... work with the file ...
An external pointer of class "pxdoc_t" representing the opened
Paradox file, or NULL if the file could not be opened (with a warning).
# Example 1: Open a bundled demo file (biolife.db) db_path <- system.file("extdata", "biolife.db", package = "Rparadox") pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { # normally you'd read data here pxlib_close_file(pxdoc) } # Example 2: Open a file with overridden encoding (of_cp866.db) db_path2 <- system.file("extdata", "of_cp866.db", package = "Rparadox") pxdoc2 <- pxlib_open_file(db_path2, encoding = "cp866") if (!is.null(pxdoc2)) { # read some data ... pxlib_close_file(pxdoc2) } # Example 3: Open an encrypted file with password db_path3 <- system.file("extdata", "country_encrypted.db", package = "Rparadox") px_doc <- pxlib_open_file(db_path3, password = "rparadox") data <- pxlib_get_data(px_doc) pxlib_close_file(px_doc)# Example 1: Open a bundled demo file (biolife.db) db_path <- system.file("extdata", "biolife.db", package = "Rparadox") pxdoc <- pxlib_open_file(db_path) if (!is.null(pxdoc)) { # normally you'd read data here pxlib_close_file(pxdoc) } # Example 2: Open a file with overridden encoding (of_cp866.db) db_path2 <- system.file("extdata", "of_cp866.db", package = "Rparadox") pxdoc2 <- pxlib_open_file(db_path2, encoding = "cp866") if (!is.null(pxdoc2)) { # read some data ... pxlib_close_file(pxdoc2) } # Example 3: Open an encrypted file with password db_path3 <- system.file("extdata", "country_encrypted.db", package = "Rparadox") px_doc <- pxlib_open_file(db_path3, password = "rparadox") data <- pxlib_get_data(px_doc) pxlib_close_file(px_doc)
A high-level, user-friendly wrapper function that reads an entire Paradox database file (.db) and returns its contents as a tibble.
read_paradox(path, encoding = NULL, password = NULL)read_paradox(path, encoding = NULL, password = NULL)
path |
A character string specifying the path to the Paradox (.db) file. |
encoding |
An optional character string specifying the input encoding of
the data (e.g., "cp866", "cp1252"). If |
password |
Optional character string. The password used to decrypt the Paradox file. If the file is encrypted and no password is provided, reading usually fails or returns garbage. |
This function simplifies the process of reading Paradox files by handling the complete workflow in a single call:
It validates the input path and encoding.
It safely opens a handle to the file using pxlib_open_file().
It ensures the file handle is always closed using on.exit(), even if
errors occur during data reading.
It reads the data using pxlib_get_data().
It returns a clean tibble.
If the specified file does not exist, the function will issue a warning and return an empty tibble.
A tibble containing the data from the Paradox file.
# Read the demo database in one step db_path <- system.file("extdata", "biolife.db", package = "Rparadox") if (file.exists(db_path)) { biolife_data <- read_paradox(db_path) print(biolife_data) }# Read the demo database in one step db_path <- system.file("extdata", "biolife.db", package = "Rparadox") if (file.exists(db_path)) { biolife_data <- read_paradox(db_path) print(biolife_data) }