| Title: | Bundled 'PCRE2' Regular Expressions with a C Interface |
|---|---|
| Description: | Matches regular expressions with a bundled copy of the 'PCRE2' library (<https://github.com/PCRE2Project/pcre2>), so that every platform runs the same version with its just-in-time compiler. Patterns are compiled once and cached, matching runs on several threads, and capture groups are returned as character vectors and data frames built in C. Replacements use the full 'PCRE2' substitution language, and each call can bound its work with match, depth and heap limits. Other packages reach the same library from C through LinkingTo, instead of bundling their own copy. |
| Authors: | Pedro Baltazar [aut, cre, cph], Philip Hazel [ctb, cph] (Author of PCRE2, bundled in src/vendor/pcre2), University of Cambridge [cph] (PCRE2, bundled in src/vendor/pcre2), Zoltan Herczeg [ctb, cph] (Author of the PCRE2 JIT compiler and sljit, bundled in src/vendor/pcre2), Nicholas Wilson [ctb] (PCRE2 maintainer, bundled in src/vendor/pcre2), PCRE2 contributors [cph] (see inst/COPYRIGHTS) |
| Maintainer: | Pedro Baltazar <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-12-01 09:56:51 UTC |
| Source: | https://github.com/pedrobtz/zuregex |
Every re_*() function compiles a character pattern through a cache of
recently used compiled patterns, so a pattern used again, in a loop or
across calls, is not recompiled. Patterns are keyed by their text,
flags, dialect, literal and jit. The least recently used pattern
is dropped when the cache is full. Patterns longer than 65,536 characters
are never cached.
re_cache_size(n = NULL) re_cache_clear()re_cache_size(n = NULL) re_cache_clear()
n |
|
re objects from re_compile() stay valid when the cache drops their
pattern or is cleared.
re_cache_size() returns the capacity; when setting it, the
previous capacity, invisibly. re_cache_clear() returns the number of
patterns it dropped, invisibly.
re_cache_size() old <- re_cache_size(16) re_cache_size(old) re_cache_clear()re_cache_size() old <- re_cache_size(16) re_cache_size(old) re_cache_clear()
re_compile() compiles each pattern once, with PCRE2's just-in-time
compiler where the platform allows it, and returns an re vector that
every re_*() function accepts in place of a character pattern.
Compilation goes through the pattern cache, so compiling the same pattern
again is cheap; see re_cache_size().
re_compile( pattern, flags = "", dialect = c("pcre", "js"), literal = FALSE, jit = TRUE )re_compile( pattern, flags = "", dialect = c("pcre", "js"), literal = FALSE, jit = TRUE )
pattern |
A character vector of regular expressions. |
||||||||||||||||||||||||||||
flags |
A single string of flag letters, applied to every pattern:
Each letter may appear once, and |
||||||||||||||||||||||||||||
dialect |
|
||||||||||||||||||||||||||||
literal |
If |
||||||||||||||||||||||||||||
jit |
If |
An re vector, as long as pattern.
re_info() to inspect compiled patterns, re_escape() to quote
metacharacters.
re <- re_compile(c("(\\d+)-(\\d+)", "^[a-z]+$"), flags = "i") re re_info(re) # A literal pattern needs no escaping re_compile("1+1=2", literal = TRUE)re <- re_compile(c("(\\d+)-(\\d+)", "^[a-z]+$"), flags = "i") re re_info(re) # A literal pattern needs no escaping re_compile("1+1=2", literal = TRUE)
A short pattern can compile to a very large program: counted repeats of
a group copy the group, so nested ones multiply. A 77-character pattern
with three nested {253} repeats compiles to 458 MB. zuregex refuses
any pattern whose compiled form would exceed the cap, with a
zuregex_error_compile, before PCRE2 allocates the memory.
re_compile_size(bytes = NULL)re_compile_size(bytes = NULL)
bytes |
|
The default, 16 MiB, is about a hundred times the largest realistic
pattern: an alternation of keywords at the cache's 65,536-character
limit compiles to about 150 KB. The cap bounds compiling only; to bound
matching, use re_limits().
The cap applies to every compile in the session, including compiles
through the C API. A pattern already in the cache keeps working when the
cap is lowered; re_cache_clear() drops it. An re object's pattern is
compiled again for bytes subjects and after readRDS(), and that compile
is held to the cap of the moment, so an object made under a higher cap
may refuse raw subjects once the cap is lowered.
The cap in bytes. When setting it, the previous cap, invisibly.
re_compile_size() try(re_compile("(?:(?:(?:ab|cd){200}){200}){200}")) old <- re_compile_size(2^30) re_compile_size(old)re_compile_size() try(re_compile("(?:(?:(?:ab|cd){200}){200}){200}")) old <- re_compile_size(2^30) re_compile_size(old)
re_detect() reports whether each element of x matches its pattern.
re_count() counts the non-overlapping matches in each element.
re_detect( x, pattern, anchor = c("none", "start", "full"), negate = FALSE, flags = "", literal = FALSE, limits = NULL ) re_count(x, pattern, flags = "", literal = FALSE, limits = NULL)re_detect( x, pattern, anchor = c("none", "start", "full"), negate = FALSE, flags = "", literal = FALSE, limits = NULL ) re_count(x, pattern, flags = "", literal = FALSE, limits = NULL)
x |
A character vector, a raw vector, or a list of raw vectors.
|
pattern |
A character vector or an |
anchor |
Where a match must be: |
negate |
If |
flags |
A single string of flag letters for pattern strings, such as
|
literal |
If |
limits |
A |
re_detect(): a logical vector, one per subject. re_count():
an integer vector, one per subject.
pattern is a character vector of regular expressions, compiled through
the cache with flags and literal, or an re vector from
re_compile(), which carries its own flags and can use the JavaScript
dialect. It has length 1, used for every element of x, or exactly the
length of x, pairing pattern[i] with x[i]. Any other length is an
error: nothing is recycled. An NA pattern gives NA for its element.
Base R's options map onto these arguments: ignore.case = TRUE is
flags = "i", fixed = TRUE is literal = TRUE, invert = TRUE is
re_detect(negate = TRUE), and useBytes = TRUE is a raw vector or
strings marked as "bytes" (see Strings and bytes). perl = TRUE is
always on.
Character input is matched as UTF-8; strings in other declared encodings
are translated first. Invalid UTF-8 is an error of class
zuregex_error_utf. A raw vector is one subject matched as bytes, as is
each element of a list of raw vectors, and so is a character vector with
any element marked as "bytes". Patterns are then compiled without UTF-8
support, so . matches one byte. \\C, which matches one byte, is
allowed only then: in a UTF-8 pattern it is a compile error, since it
could split a character. A bytes pattern may not turn UTF-8 back on with
(*UTF).
x <- c("apple", "banana", "cherry", NA) re_detect(x, "an") re_detect(x, "a|b", anchor = "start") re_count(x, "[aeiou]") re_detect(x, "APPLE", flags = "i") re_count("a.b.c", ".", literal = TRUE) # One pattern per element re_detect(c("abc", "abc"), c("^a", "^b"))x <- c("apple", "banana", "cherry", NA) re_detect(x, "an") re_detect(x, "a|b", anchor = "start") re_count(x, "[aeiou]") re_detect(x, "APPLE", flags = "i") re_count("a.b.c", ".", literal = TRUE) # One pattern per element re_detect(c("abc", "abc"), c("^a", "^b"))
Escapes every character that has a meaning in a PCRE2 pattern, so that
the result matches x literally, as Go's QuoteMeta() does. The result
is also literal under the x flag, which gives whitespace and # a
meaning. To match a whole pattern literally, literal = TRUE in
re_compile() is simpler.
re_escape(x)re_escape(x)
x |
A character vector. |
A character vector as long as x, in UTF-8.
re_escape("1+1=2 (really?)")re_escape("1+1=2 (really?)")
re_extract() returns the first match in each element of x, or one of
its groups; re_extract_all() returns every match. re_match() returns
every group of the first match as a data frame with one row per element;
re_match_all() returns one row per match. The strings are built in C,
without the per-match R overhead of regmatches() or
utils::strcapture().
re_extract(x, pattern, group = 0, flags = "", literal = FALSE, limits = NULL) re_extract_all( x, pattern, group = 0, n = Inf, flags = "", literal = FALSE, limits = NULL ) re_match(x, pattern, proto = NULL, flags = "", literal = FALSE, limits = NULL) re_match_all(x, pattern, n = Inf, flags = "", literal = FALSE, limits = NULL)re_extract(x, pattern, group = 0, flags = "", literal = FALSE, limits = NULL) re_extract_all( x, pattern, group = 0, n = Inf, flags = "", literal = FALSE, limits = NULL ) re_match(x, pattern, proto = NULL, flags = "", literal = FALSE, limits = NULL) re_match_all(x, pattern, n = Inf, flags = "", literal = FALSE, limits = NULL)
x |
A character vector, a raw vector, or a list of raw vectors.
|
pattern |
A character vector or an |
group |
The group to extract: a number, 0 for the whole match, or a group name. |
flags |
A single string of flag letters for pattern strings, such as
|
literal |
If |
limits |
A |
n |
The most matches to return per element, |
proto |
|
re_extract(): a character vector, NA where there is no match.
re_extract_all(): a list of character vectors, NA for an NA
subject or pattern.
re_match(): a data frame with one row per subject and one column per
group, all NA where there is no match. re_match_all(): a data frame
with element and match columns, then one column per group, one row
per match; a subject with no match has no rows, and an NA subject or
pattern one row of NA. A group named element or match repeats
that column's name, so $ gives the leading column; index the group
by position instead.
Strings from character input are in UTF-8; from bytes they are marked
as "bytes".
Groups are numbered from 1; group 0 is the whole match. In re_match()
a named group's column takes its name and an unnamed group's column its
number, so (?<year>\\d+)-(\\d+) gives the columns year and 2. A
group that did not take part in the match is NA.
With one pattern per element, the columns are the union of the
patterns' groups in order of first appearance: groups with the same
name share a column, unnamed groups share a column by position, and an
element whose pattern lacks a group has NA there.
pattern is a character vector of regular expressions, compiled through
the cache with flags and literal, or an re vector from
re_compile(), which carries its own flags and can use the JavaScript
dialect. It has length 1, used for every element of x, or exactly the
length of x, pairing pattern[i] with x[i]. Any other length is an
error: nothing is recycled. An NA pattern gives NA for its element.
Base R's options map onto these arguments: ignore.case = TRUE is
flags = "i", fixed = TRUE is literal = TRUE, invert = TRUE is
re_detect(negate = TRUE), and useBytes = TRUE is a raw vector or
strings marked as "bytes" (see Strings and bytes). perl = TRUE is
always on.
Character input is matched as UTF-8; strings in other declared encodings
are translated first. Invalid UTF-8 is an error of class
zuregex_error_utf. A raw vector is one subject matched as bytes, as is
each element of a list of raw vectors, and so is a character vector with
any element marked as "bytes". Patterns are then compiled without UTF-8
support, so . matches one byte. \\C, which matches one byte, is
allowed only then: in a UTF-8 pattern it is a compile error, since it
could split a character. A bytes pattern may not turn UTF-8 back on with
(*UTF).
x <- c("2026-10-21", "1999-01-02 and 2000-03-04", "none", NA) re_extract(x, "\\d{4}") re_extract(x, "(?<year>\\d{4})-(\\d{2})", group = "year") re_extract_all(x, "\\d{4}") re_match(x, "(?<year>\\d{4})-(?<month>\\d{2})") re_match(x, "(\\d{4})-(\\d{2})", proto = data.frame(year = 0L, month = 0L)) re_match_all(x, "(?<year>\\d{4})")x <- c("2026-10-21", "1999-01-02 and 2000-03-04", "none", NA) re_extract(x, "\\d{4}") re_extract(x, "(?<year>\\d{4})-(\\d{2})", group = "year") re_extract_all(x, "\\d{4}") re_match(x, "(?<year>\\d{4})-(?<month>\\d{2})") re_match(x, "(\\d{4})-(\\d{2})", proto = data.frame(year = 0L, month = 0L)) re_match_all(x, "(?<year>\\d{4})")
Reports what PCRE2 recorded when it compiled each pattern.
re_info(re)re_info(re)
re |
An |
A data frame with one row per pattern and columns:
pattern, flags, dialect, literal: what was compiled. flags
is rebuilt from PCRE2's options, in a canonical order.
groups: the number of capture groups.
group_names: a list column; for each pattern, a character vector
with one name per group, "" for unnamed groups.
jit: whether the pattern runs JIT-compiled code.
min_length: a lower bound on the length of a match, in characters.
prefix: a literal string every match starts with, "" when there
is none or it cannot be determined simply. It may be shorter than the
longest such string.
backrefs: whether the pattern has back-references.
pcre2_version: the PCRE2 version that compiled it.
An NA pattern gives a row of NA.
re_info(re_compile(c("(?<year>\\d{4})-(\\d{2})", "abc+")))re_info(re_compile(c("(?<year>\\d{4})-(\\d{2})", "abc+")))
PCRE2 matches by backtracking, so a pattern such as ^(a+)+$ can take
time exponential in the length of the subject. zuregex makes no
linear-time promise; for that, use the re2 package. What it promises is
that limits bound the work per element, and that hitting one is either a
classed error or an NA you asked for.
re_limits(match = NULL, depth = NULL, heap = NULL, on_limit = c("error", "na"))re_limits(match = NULL, depth = NULL, heap = NULL, on_limit = c("error", "na"))
match |
The most times PCRE2's internal match function may be called for one search; PCRE2's default is 10,000,000. The JIT compiler honours it too. |
depth |
The deepest backtracking nesting for one search; PCRE2's
default equals |
heap |
The most heap memory, in kibibytes, the interpreter may use for backtracking in one search; PCRE2's default is 20,000,000. The JIT compiler ignores it. |
on_limit |
What an element that hits a limit gives: |
Pass re_limits() as limits = to any matching function, or set it for
the session with options(zuregex.limits = re_limits(...)). The argument
wins over the option. NULL keeps PCRE2's default for that limit.
An object of class re_limits.
# No match, but only after trying every way to split the a's x <- paste0(strrep("a", 30), "!") try(re_detect(x, "^(a+)+$", limits = re_limits(match = 1000))) re_detect( c(x, "aaa"), "^(a+)+$", limits = re_limits(match = 1000, on_limit = "na") ) old <- options(zuregex.limits = re_limits(match = 1e5)) options(old)# No match, but only after trying every way to split the a's x <- paste0(strrep("a", 30), "!") try(re_detect(x, "^(a+)+$", limits = re_limits(match = 1000))) re_detect( c(x, "aaa"), "^(a+)+$", limits = re_limits(match = 1000, on_limit = "na") ) old <- options(zuregex.limits = re_limits(match = 1e5)) options(old)
re_locate() finds the first match in each element of x;
re_locate_all() finds every match.
re_locate( x, pattern, bytes = FALSE, flags = "", literal = FALSE, limits = NULL ) re_locate_all( x, pattern, n = Inf, overlap = FALSE, bytes = FALSE, flags = "", literal = FALSE, limits = NULL )re_locate( x, pattern, bytes = FALSE, flags = "", literal = FALSE, limits = NULL ) re_locate_all( x, pattern, n = Inf, overlap = FALSE, bytes = FALSE, flags = "", literal = FALSE, limits = NULL )
x |
A character vector, a raw vector, or a list of raw vectors.
|
pattern |
A character vector or an |
bytes |
If |
flags |
A single string of flag letters for pattern strings, such as
|
literal |
If |
limits |
A |
n |
The most matches to return per element, |
overlap |
If |
Offsets are one-based and inclusive, as regexpr() and
stringr::str_locate() report them, so substr(x, start, end) extracts
a match, and for raw input so does x[start:end]. An empty match at
position k has start = k and end = k - 1. Offsets count characters,
or bytes with bytes = TRUE; for raw input the two are the same.
After an empty match, the next search follows the pattern's dialect: for
"pcre" PCRE2's rule, which first tries for a non-empty match at the
same position, and for "js" JavaScript's, which moves on one
character.
re_locate(): an integer matrix with columns start and end
and one row per subject, NA where there is no match.
re_locate_all(): a data frame with one row per match and columns
element (the subject's index), match (the match's number within
the element), start and end. A subject with no match has no rows;
an NA subject or pattern has one row with match, start and end
NA.
pattern is a character vector of regular expressions, compiled through
the cache with flags and literal, or an re vector from
re_compile(), which carries its own flags and can use the JavaScript
dialect. It has length 1, used for every element of x, or exactly the
length of x, pairing pattern[i] with x[i]. Any other length is an
error: nothing is recycled. An NA pattern gives NA for its element.
Base R's options map onto these arguments: ignore.case = TRUE is
flags = "i", fixed = TRUE is literal = TRUE, invert = TRUE is
re_detect(negate = TRUE), and useBytes = TRUE is a raw vector or
strings marked as "bytes" (see Strings and bytes). perl = TRUE is
always on.
Character input is matched as UTF-8; strings in other declared encodings
are translated first. Invalid UTF-8 is an error of class
zuregex_error_utf. A raw vector is one subject matched as bytes, as is
each element of a list of raw vectors, and so is a character vector with
any element marked as "bytes". Patterns are then compiled without UTF-8
support, so . matches one byte. \\C, which matches one byte, is
allowed only then: in a UTF-8 pattern it is a compile error, since it
could split a character. A bytes pattern may not turn UTF-8 back on with
(*UTF).
x <- c("apple pie", "banana", NA) loc <- re_locate(x, "an+") loc substr(x, loc[, "start"], loc[, "end"]) re_locate_all(x, "[aeiou]") re_locate_all("aaaa", "aa", overlap = TRUE)x <- c("apple pie", "banana", NA) loc <- re_locate(x, "an+") loc substr(x, loc[, "start"], loc[, "end"]) re_locate_all(x, "[aeiou]") re_locate_all("aaaa", "aa", overlap = TRUE)
re_replace() replaces matches in each element of x, all of them by
default. re_expand() returns a template expanded with each element's
first match, as Python's Match.expand() does.
re_replace( x, pattern, replacement, n = Inf, syntax = c("extended", "literal"), flags = "", literal = FALSE, limits = NULL ) re_expand(x, pattern, template, flags = "", literal = FALSE, limits = NULL)re_replace( x, pattern, replacement, n = Inf, syntax = c("extended", "literal"), flags = "", literal = FALSE, limits = NULL ) re_expand(x, pattern, template, flags = "", literal = FALSE, limits = NULL)
x |
A character vector, a raw vector, or a list of raw vectors.
|
pattern |
A character vector or an |
replacement |
A character vector of templates, of length 1 or the
length of |
n |
The most matches to replace per element, |
syntax |
|
flags |
A single string of flag letters for pattern strings, such as
|
literal |
If |
limits |
A |
template |
A character vector of templates, of length 1 or the
length of |
A character vector as long as x. Elements without a match are
returned unchanged by re_replace() and as NA by re_expand().
Other strings are in UTF-8, or marked as "bytes" for bytes input.
With syntax = "extended", the default, templates use PCRE2's extended
substitution syntax:
| Template | Meaning |
$1, ${12}, ${name} |
A group by number, past nine, or by name. $0 is the whole match. |
\1, \g<1>, \g<name> |
A group, as in base R or Python. |
${1:-none} |
The group, or none when it did not take part in the match. |
${1:+yes:no} |
yes when the group took part, otherwise no. |
\U...\E, \L...\E, \u, \l |
Upper or lower case until \E, or for one character. |
$$, \$ |
A literal $.
|
A backslash and digits are read as in a pattern. So \12 is group 12
only when the pattern has 12 groups, and otherwise the octal escape for
a newline. Prefer ${12} past nine. In an R string each backslash is
doubled, as in "\\1".
A group that did not take part in the match is replaced by "". A
reference to a group that does not exist, or a malformed template,
raises zuregex_error_template when a match first uses it. With
syntax = "literal" the replacement is inserted as it is.
replacement may be a function. It is called once for the whole call,
if anything matched, with a data frame of every match: element,
match (its number within the element), 0 (the matched text) and one
column per group, named as in re_match(). A group named element,
match or 0 repeats that column's name, as in re_match_all(). It must
return a character vector with one replacement per row.
pattern is a character vector of regular expressions, compiled through
the cache with flags and literal, or an re vector from
re_compile(), which carries its own flags and can use the JavaScript
dialect. It has length 1, used for every element of x, or exactly the
length of x, pairing pattern[i] with x[i]. Any other length is an
error: nothing is recycled. An NA pattern gives NA for its element.
Base R's options map onto these arguments: ignore.case = TRUE is
flags = "i", fixed = TRUE is literal = TRUE, invert = TRUE is
re_detect(negate = TRUE), and useBytes = TRUE is a raw vector or
strings marked as "bytes" (see Strings and bytes). perl = TRUE is
always on.
Character input is matched as UTF-8; strings in other declared encodings
are translated first. Invalid UTF-8 is an error of class
zuregex_error_utf. A raw vector is one subject matched as bytes, as is
each element of a list of raw vectors, and so is a character vector with
any element marked as "bytes". Patterns are then compiled without UTF-8
support, so . matches one byte. \\C, which matches one byte, is
allowed only then: in a UTF-8 pattern it is a compile error, since it
could split a character. A bytes pattern may not turn UTF-8 back on with
(*UTF).
x <- c("2026-10-21", "no date", NA) re_replace(x, "(\\d{4})-(\\d{2})-(\\d{2})", "$3/$2/$1") re_replace(x, "(?<y>\\d{4})", "${y}!") re_replace("hello world", "(\\w+)", "\\u$1") re_replace("a1b22", "\\d+", function(m) strrep("#", nchar(m[["0"]]))) re_expand("John Smith", "(\\w+) (\\w+)", "$2, $1")x <- c("2026-10-21", "no date", NA) re_replace(x, "(\\d{4})-(\\d{2})-(\\d{2})", "$3/$2/$1") re_replace(x, "(?<y>\\d{4})", "${y}!") re_replace("hello world", "(\\w+)", "\\u$1") re_replace("a1b22", "\\d+", function(m) strrep("#", nchar(m[["0"]]))) re_expand("John Smith", "(\\w+) (\\w+)", "$2, $1")
Splits each element of x at the matches of pattern, as Python's
re.split() does: an empty match splits too, and with
keep_groups = TRUE each separator's groups are kept between the pieces.
re_split( x, pattern, n = Inf, keep_groups = FALSE, flags = "", literal = FALSE, limits = NULL )re_split( x, pattern, n = Inf, keep_groups = FALSE, flags = "", literal = FALSE, limits = NULL )
x |
A character vector, a raw vector, or a list of raw vectors.
|
pattern |
A character vector or an |
n |
The most pieces per element, |
keep_groups |
If |
flags |
A single string of flag letters for pattern strings, such as
|
literal |
If |
limits |
A |
A list as long as x of character vectors; NA for an NA
subject or pattern.
pattern is a character vector of regular expressions, compiled through
the cache with flags and literal, or an re vector from
re_compile(), which carries its own flags and can use the JavaScript
dialect. It has length 1, used for every element of x, or exactly the
length of x, pairing pattern[i] with x[i]. Any other length is an
error: nothing is recycled. An NA pattern gives NA for its element.
Base R's options map onto these arguments: ignore.case = TRUE is
flags = "i", fixed = TRUE is literal = TRUE, invert = TRUE is
re_detect(negate = TRUE), and useBytes = TRUE is a raw vector or
strings marked as "bytes" (see Strings and bytes). perl = TRUE is
always on.
Character input is matched as UTF-8; strings in other declared encodings
are translated first. Invalid UTF-8 is an error of class
zuregex_error_utf. A raw vector is one subject matched as bytes, as is
each element of a list of raw vectors, and so is a character vector with
any element marked as "bytes". Patterns are then compiled without UTF-8
support, so . matches one byte. \\C, which matches one byte, is
allowed only then: in a UTF-8 pattern it is a compile error, since it
could split a character. A bytes pattern may not turn UTF-8 back on with
(*UTF).
re_split(c("a, b,c", "d"), ",\\s*") re_split("a1b22c", "(\\d+)", keep_groups = TRUE) re_split("a-b-c-d", "-", n = 2)re_split(c("a, b,c", "d"), ",\\s*") re_split("a1b22c", "(\\d+)", keep_groups = TRUE) re_split("a-b-c-d", "-", n = 2)
Matching runs on several threads with OpenMP when a call's subjects add
up to more than an internal size threshold, and on one thread below it.
re_threads() reports the most threads a call may use;
re_threads(n) caps it for the rest of the session. The cap applies only
to zuregex's own matching, not to other OpenMP code in the process.
re_threads(n = NULL)re_threads(n = NULL)
n |
|
Results never depend on the number of threads, so this is a performance
control, not a reproducibility one. In a build without OpenMP the value is
always 1 and a cap has no effect; zuregex_info() reports which build
this is.
A forked child, such as a worker of parallel::mclapply(), matches on
one thread, because GNU OpenMP can hang in a child whose parent has used
it.
Querying returns the effective maximum as an integer. Setting
returns the previous cap invisibly, 0 meaning none was set, so
old <- re_threads(1); re_threads(old) restores it exactly.
re_threads() old <- re_threads(1) re_threads(old)re_threads() old <- re_threads(1) re_threads(old)
Reports the version of PCRE2 that zuregex was built with, whether its just-in-time (JIT) compiler works on this machine, and how matching is set up: OpenMP, the threads and cores it can use, the input size it starts at, and the cache size.
zuregex_info()zuregex_info()
The JIT compiler can be built in and still fail at run time, on a CPU it
does not support or where the system refuses executable memory. PCRE2
then matches with its interpreter, which gives the same results more
slowly. jit_usable tells the two cases apart by JIT-compiling a small
pattern.
A list with elements:
pcre2_version: the bundled PCRE2 version, such as "10.49".
pcre2_date: its release date.
unicode: whether Unicode and UTF-8 support is built in.
unicode_version: the Unicode version of PCRE2's character tables.
jit: whether the JIT compiler is built in.
jit_usable: whether the JIT compiler works on this machine.
jit_target: the architecture the JIT compiler generates code for,
or NA without it.
openmp: whether this build matches on several threads. On macOS
that needs the OpenMP headers from
https://mac.r-project.org/openmp/ when zuregex is built.
threads: the most threads a call may use; see re_threads().
cores: the processors OpenMP sees, or NA without OpenMP.
serial_bytes: the total size of a call's subjects, in bytes, below
which it runs on one thread, because starting threads would cost
more than they save.
cache_size: the pattern cache's capacity; see re_cache_size().
zuregex_info()zuregex_info()