| Title: | Access and Visualize Integer Sequences from the OEIS |
|---|---|
| Description: | Programmatic access, analysis, and visualization of integer sequences from the On-Line Encyclopedia of Integer Sequences (OEIS) <https://oeis.org>. Fetches sequence metadata and b-files, stores terms as arbitrary-precision integers via 'gmp', and plots them with 'ggplot2'. |
| Authors: | Enrique Pérez Herrero [aut, cre] |
| Maintainer: | Enrique Pérez Herrero <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.1 |
| Built: | 2026-10-13 23:43:03 UTC |
| Source: | https://github.com/oeistools/oeis-tools-r |
OEIS B-file Class
BFile(oeis_id)BFile(oeis_id)
oeis_id |
Character string (e.g., "A000045") Downloads the b-file (list of |
An object of class "BFile"
primes <- BFile("A000040") primesprimes <- BFile("A000040") primes
Validates that the OEIS ID follows the format: A followed by exactly 6 digits
check_id(oeis_id)check_id(oeis_id)
oeis_id |
Character string to validate |
Logical TRUE if valid, FALSE otherwise
check_id("A000045") # TRUE check_id("invalid") # FALSEcheck_id("A000045") # TRUE check_id("invalid") # FALSE
Writes sequence values in the standard b-file format ("n a(n)", one pair per line).
create_bfile(oeis_id, data, offset = 1L, output_path)create_bfile(oeis_id, data, offset = 1L, output_path)
oeis_id |
Character string (e.g., "A213676") |
data |
Vector of sequence values (numeric, integer, character, or
|
offset |
Integer starting index. Defaults to 1 |
output_path |
Directory or exact file path to save the b-file. When a directory is given, the standard b-file name (e.g., "b213676.txt") is used inside it |
Character string: the path to the created b-file
path <- create_bfile("A000045", c(0, 1, 1, 2, 3, 5, 8), offset = 0, output_path = tempdir()) readLines(path) unlink(path)path <- create_bfile("A000045", c(0, 1, 1, 2, 3, 5, 8), offset = 0, output_path = tempdir()) readLines(path) unlink(path)
Extract OEIS IDs from text
extract_oeis_ids(text)extract_oeis_ids(text)
text |
Character string to search |
Character vector of OEIS IDs
extract_oeis_ids("Cf. A000045, A000032 and A000045.")extract_oeis_ids("Cf. A000045, A000032 and A000045.")
Get B-file Data
get_bfile_data(bfile)get_bfile_data(bfile)
bfile |
A BFile object |
A gmp::bigz vector or NULL
primes <- BFile("A000040") head(get_bfile_data(primes))primes <- BFile("A000040") head(get_bfile_data(primes))
Get B-file Indices
get_bfile_indices(bfile)get_bfile_indices(bfile)
bfile |
A BFile object |
Integer vector of the first-column indices, or NULL when parsing failed
primes <- BFile("A000040") head(get_bfile_indices(primes))primes <- BFile("A000040") head(get_bfile_indices(primes))
Get B-file Information
get_bfile_info(seq)get_bfile_info(seq)
seq |
A Sequence object |
List with b-file metadata: available, filename, url, length, first, last, min, max
fib <- Sequence("A000045") get_bfile_info(fib)fib <- Sequence("A000045") get_bfile_info(fib)
Build a BibTeX @misc entry citing this OEIS sequence
get_bibtex(seq)get_bibtex(seq)
seq |
A Sequence object |
Character string with a BibTeX @misc entry
fib <- Sequence("A000045") cat(get_bibtex(fib))fib <- Sequence("A000045") cat(get_bibtex(fib))
Return the parsed sequence data terms
get_data_values(seq)get_data_values(seq)
seq |
A Sequence object |
A gmp::bigz vector of terms
fib <- Sequence("A000045") get_data_values(fib)[1:10]fib <- Sequence("A000045") get_data_values(fib)[1:10]
Get B-file Filename
get_filename(bfile)get_filename(bfile)
bfile |
A BFile object |
Character string
primes <- BFile("A000040") get_filename(primes)primes <- BFile("A000040") get_filename(primes)
Uses IRdisplay::display_png() when running inside a Jupyter/IRkernel
session;
otherwise returns the raw PNG bytes.
get_graph_image( seq, width = NULL, height = NULL, timeout = 10, use_cache = TRUE )get_graph_image( seq, width = NULL, height = NULL, timeout = 10, use_cache = TRUE )
seq |
A Sequence object |
width |
Optional display width in pixels |
height |
Optional display height in pixels |
timeout |
Numeric timeout in seconds |
use_cache |
Logical; reuse a previously downloaded PNG when TRUE |
Raw vector of PNG bytes (invisibly, when displayed via IRdisplay)
fib <- Sequence("A000045") img <- get_graph_image(fib)fib <- Sequence("A000045") img <- get_graph_image(fib)
Download the OEIS graph image as PNG bytes
get_graph_png(seq, timeout = 10, use_cache = TRUE)get_graph_png(seq, timeout = 10, use_cache = TRUE)
seq |
A Sequence object |
timeout |
Numeric timeout in seconds |
use_cache |
Logical; reuse a previously downloaded PNG when TRUE (default) |
Raw vector of PNG bytes
fib <- Sequence("A000045") png_bytes <- get_graph_png(fib) length(png_bytes)fib <- Sequence("A000045") png_bytes <- get_graph_png(fib) length(png_bytes)
Instance-method wrapper around oeis_keyword_description().
get_keyword_description(seq, keyword_tag)get_keyword_description(seq, keyword_tag)
seq |
A Sequence object |
keyword_tag |
Character string |
Character string with description, or NULL
fib <- Sequence("A000045") get_keyword_description(fib, fib$keyword[1])fib <- Sequence("A000045") get_keyword_description(fib, fib$keyword[1])
Get B-file URL
get_url(bfile)get_url(bfile)
bfile |
A BFile object |
Character string
primes <- BFile("A000040") get_url(primes)primes <- BFile("A000040") get_url(primes)
Extract cross-reference IDs
get_xref_ids(seq)get_xref_ids(seq)
seq |
A Sequence object |
Character vector of unique OEIS IDs, in first-seen order
fib <- Sequence("A000045") head(get_xref_ids(fib))fib <- Sequence("A000045") head(get_xref_ids(fib))
Sends a small request to the OEIS search API. Useful to guard code that needs the network, since the OEIS may be down or may refuse requests from some hosts (for example, cloud or continuous-integration servers).
oeis_available(timeout = 5)oeis_available(timeout = 5)
timeout |
Numeric timeout in seconds |
TRUE if the OEIS answered successfully, FALSE otherwise
oeis_available()oeis_available()
Generate OEIS b-file filename
oeis_bfile(oeis_id)oeis_bfile(oeis_id)
oeis_id |
Character string (e.g., "A000045") |
Character string (e.g., "b000045.txt")
oeis_bfile("A000045")oeis_bfile("A000045")
Get OEIS keyword description
oeis_keyword_description(keyword_tag)oeis_keyword_description(keyword_tag)
keyword_tag |
Character string |
Character string with description or NULL
oeis_keyword_description("core") oeis_keyword_description("nonn")oeis_keyword_description("core") oeis_keyword_description("nonn")
Plot B-file Data
plot_data(bfile, n = NULL, plot_style = "line", ...) ## S3 method for class 'BFile' plot_data( bfile, n = NULL, plot_style = "line", p = NULL, show = TRUE, return_plot = FALSE, ... )plot_data(bfile, n = NULL, plot_style = "line", ...) ## S3 method for class 'BFile' plot_data( bfile, n = NULL, plot_style = "line", p = NULL, show = TRUE, return_plot = FALSE, ... )
bfile |
A BFile object |
n |
Number of leading points to plot. When NULL (default), all available points are plotted |
plot_style |
One of "line" (default), "joined" (alias for "line"), or "scatter" |
... |
Additional aesthetic parameters forwarded to |
p |
An existing ggplot object to layer onto, or NULL to create a new plot |
show |
Logical; print the plot when TRUE (default) |
return_plot |
Logical; return the ggplot object when TRUE. Defaults to FALSE |
A ggplot2 plot object when return_plot = TRUE; otherwise
invisible NULL
primes <- BFile("A000040") plot_data(primes, n = 100, plot_style = "scatter") g <- plot_data(primes, n = 100, show = FALSE, return_plot = TRUE)primes <- BFile("A000040") plot_data(primes, n = 100, plot_style = "scatter") g <- plot_data(primes, n = 100, show = FALSE, return_plot = TRUE)
Prefers the sequence's embedded b-file (richer, longer) and falls back to the terms parsed from the OEIS JSON entry.
## S3 method for class 'Sequence' plot(x, ...)## S3 method for class 'Sequence' plot(x, ...)
x |
A Sequence object |
... |
Additional arguments passed to |
The value returned by plot_data(): a ggplot object when
return_plot = TRUE, otherwise invisible NULL
fib <- Sequence("A000045") plot(fib, n = 50)fib <- Sequence("A000045") plot(fib, n = 50)
OEIS Sequence Class
Sequence(oeis_id)Sequence(oeis_id)
oeis_id |
Character string (e.g., "A000045") |
An object of class "Sequence"
Fetches an OEIS entry (and its b-file) over the internet.
fib <- Sequence("A000045") fib$namefib <- Sequence("A000045") fib$name