| Title: | Access and Visualize Integer Sequences from the OEIS |
| Version: | 0.3.1 |
| 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'. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Language: | en-US |
| Depends: | R (≥ 4.1.0) |
| Imports: | httr2 (≥ 0.2.0), jsonlite (≥ 1.8.0), ggplot2 (≥ 3.4.0), gmp (≥ 0.7-0) |
| Suggests: | testthat (≥ 3.2.0), knitr, rmarkdown, lintr, IRdisplay, withr |
| URL: | https://github.com/oeistools/oeis-tools-R |
| BugReports: | https://github.com/oeistools/oeis-tools-R/issues |
| VignetteBuilder: | knitr |
| Config/roxygen2/version: | 8.1.0 |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-26 10:01:30 UTC; eph |
| Author: | Enrique Pérez Herrero [aut, cre] |
| Maintainer: | Enrique Pérez Herrero <energycode.org@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-07 07:50:02 UTC |
OEIS B-file Class
Description
OEIS B-file Class
Usage
BFile(oeis_id)
Arguments
oeis_id |
Character string (e.g., "A000045") Downloads the b-file (list of |
Value
An object of class "BFile"
Examples
primes <- BFile("A000040")
primes
OEIS URL constant
Description
OEIS URL constant
Generate OEIS URL
Usage
OEIS_URL
oeis_url(oeis_id, fmt = NULL)
Arguments
oeis_id |
Character string (e.g., "A000045") |
fmt |
Character string: "json", "text", "bfile", "graph", or NULL |
Value
Character string containing the URL
Examples
oeis_url("A000045")
oeis_url("A000045", fmt = "json")
OEIS Sequence Class
Description
OEIS Sequence Class
Usage
Sequence(oeis_id)
Arguments
oeis_id |
Character string (e.g., "A000045") |
Value
An object of class "Sequence"
Fetches an OEIS entry (and its b-file) over the internet.
Examples
fib <- Sequence("A000045")
fib$name
Check if an OEIS ID is valid
Description
Validates that the OEIS ID follows the format: A followed by exactly 6 digits
Usage
check_id(oeis_id)
Arguments
oeis_id |
Character string to validate |
Value
Logical TRUE if valid, FALSE otherwise
Examples
check_id("A000045") # TRUE
check_id("invalid") # FALSE
Create a b-file text file for an OEIS sequence
Description
Writes sequence values in the standard b-file format ("n a(n)", one pair per line).
Usage
create_bfile(oeis_id, data, offset = 1L, output_path)
Arguments
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 |
Value
Character string: the path to the created b-file
Examples
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
Description
Extract OEIS IDs from text
Usage
extract_oeis_ids(text)
Arguments
text |
Character string to search |
Value
Character vector of OEIS IDs
Examples
extract_oeis_ids("Cf. A000045, A000032 and A000045.")
Get B-file Data
Description
Get B-file Data
Usage
get_bfile_data(bfile)
Arguments
bfile |
A BFile object |
Value
A gmp::bigz vector or NULL
Examples
primes <- BFile("A000040")
head(get_bfile_data(primes))
Get B-file Indices
Description
Get B-file Indices
Usage
get_bfile_indices(bfile)
Arguments
bfile |
A BFile object |
Value
Integer vector of the first-column indices, or NULL when parsing failed
Examples
primes <- BFile("A000040")
head(get_bfile_indices(primes))
Get B-file Information
Description
Get B-file Information
Usage
get_bfile_info(seq)
Arguments
seq |
A Sequence object |
Value
List with b-file metadata: available, filename, url, length, first, last, min, max
Examples
fib <- Sequence("A000045")
get_bfile_info(fib)
Build a BibTeX @misc entry citing this OEIS sequence
Description
Build a BibTeX @misc entry citing this OEIS sequence
Usage
get_bibtex(seq)
Arguments
seq |
A Sequence object |
Value
Character string with a BibTeX @misc entry
Examples
fib <- Sequence("A000045")
cat(get_bibtex(fib))
Return the parsed sequence data terms
Description
Return the parsed sequence data terms
Usage
get_data_values(seq)
Arguments
seq |
A Sequence object |
Value
A gmp::bigz vector of terms
Examples
fib <- Sequence("A000045")
get_data_values(fib)[1:10]
Get B-file Filename
Description
Get B-file Filename
Usage
get_filename(bfile)
Arguments
bfile |
A BFile object |
Value
Character string
Examples
primes <- BFile("A000040")
get_filename(primes)
Retrieve the OEIS graph image for display
Description
Uses IRdisplay::display_png() when running inside a Jupyter/IRkernel
session;
otherwise returns the raw PNG bytes.
Usage
get_graph_image(
seq,
width = NULL,
height = NULL,
timeout = 10,
use_cache = TRUE
)
Arguments
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 |
Value
Raw vector of PNG bytes (invisibly, when displayed via IRdisplay)
Examples
fib <- Sequence("A000045")
img <- get_graph_image(fib)
Download the OEIS graph image as PNG bytes
Description
Download the OEIS graph image as PNG bytes
Usage
get_graph_png(seq, timeout = 10, use_cache = TRUE)
Arguments
seq |
A Sequence object |
timeout |
Numeric timeout in seconds |
use_cache |
Logical; reuse a previously downloaded PNG when TRUE (default) |
Value
Raw vector of PNG bytes
Examples
fib <- Sequence("A000045")
png_bytes <- get_graph_png(fib)
length(png_bytes)
Return the OEIS keyword description for a given tag
Description
Instance-method wrapper around oeis_keyword_description().
Usage
get_keyword_description(seq, keyword_tag)
Arguments
seq |
A Sequence object |
keyword_tag |
Character string |
Value
Character string with description, or NULL
Examples
fib <- Sequence("A000045")
get_keyword_description(fib, fib$keyword[1])
Get B-file URL
Description
Get B-file URL
Usage
get_url(bfile)
Arguments
bfile |
A BFile object |
Value
Character string
Examples
primes <- BFile("A000040")
get_url(primes)
Extract cross-reference IDs
Description
Extract cross-reference IDs
Usage
get_xref_ids(seq)
Arguments
seq |
A Sequence object |
Value
Character vector of unique OEIS IDs, in first-seen order
Examples
fib <- Sequence("A000045")
head(get_xref_ids(fib))
Check whether the OEIS web service is reachable
Description
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).
Usage
oeis_available(timeout = 5)
Arguments
timeout |
Numeric timeout in seconds |
Value
TRUE if the OEIS answered successfully, FALSE otherwise
Examples
oeis_available()
Generate OEIS b-file filename
Description
Generate OEIS b-file filename
Usage
oeis_bfile(oeis_id)
Arguments
oeis_id |
Character string (e.g., "A000045") |
Value
Character string (e.g., "b000045.txt")
Examples
oeis_bfile("A000045")
Get OEIS keyword description
Description
Get OEIS keyword description
Usage
oeis_keyword_description(keyword_tag)
Arguments
keyword_tag |
Character string |
Value
Character string with description or NULL
Examples
oeis_keyword_description("core")
oeis_keyword_description("nonn")
Plot Sequence Data
Description
Prefers the sequence's embedded b-file (richer, longer) and falls back to the terms parsed from the OEIS JSON entry.
Usage
## S3 method for class 'Sequence'
plot(x, ...)
Arguments
x |
A Sequence object |
... |
Additional arguments passed to |
Value
The value returned by plot_data(): a ggplot object when
return_plot = TRUE, otherwise invisible NULL
Examples
fib <- Sequence("A000045")
plot(fib, n = 50)
Plot B-file Data
Description
Plot B-file Data
Usage
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,
...
)
Arguments
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 |
Value
A ggplot2 plot object when return_plot = TRUE; otherwise
invisible NULL
Examples
primes <- BFile("A000040")
plot_data(primes, n = 100, plot_style = "scatter")
g <- plot_data(primes, n = 100, show = FALSE, return_plot = TRUE)