The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Getting Started with oeis.tools

library(oeis.tools)
#> oeis.tools 0.3.1 | https://github.com/oeistools/oeis-tools-R

Introduction

oeis.tools is an R interface to the Online Encyclopedia of Integer Sequences (OEIS): it fetches sequence metadata and b-files, parses them into S3 objects, and plots terms with ggplot2.

Fetching a Sequence

Sequence(oeis_id) fetches and parses an OEIS entry from the JSON API.

# Fetch the Fibonacci sequence
fib <- Sequence("A000045")

# Access basic information
fib$id
fib$name

Working with B-files

B-files contain more terms of a sequence than the main OEIS entry, often thousands.

# Get b-file data for Prime numbers
primes_bfile <- BFile("A000040")

# Access the data
data <- get_bfile_data(primes_bfile)
length(data)

Visualization

plot_data() builds a ggplot2 line or scatter plot from a BFile.

# Plot the first 100 terms of the Fibonacci sequence from its b-file
plot_data(primes_bfile, n = 100, color = "darkgreen")

Extracting Cross-References

get_xref_ids() extracts the OEIS ids referenced in a sequence’s xref field:

# Get related sequences for Fibonacci
get_xref_ids(fib)

Keyword Descriptions

oeis_keyword_description() looks up the description text for an OEIS keyword tag:

oeis_keyword_description("core")
#> [1] "A fundamental sequence."
oeis_keyword_description("nice")
#> [1] "An exceptionally nice sequence."

Arbitrary-Precision Values

Sequence and b-file terms are stored as gmp::bigz values, so terms with hundreds of digits are never truncated. plot_data() and plot.Sequence() detect when a value overflows double precision and automatically switch to a signed log10 magnitude scale.

bfile <- BFile("A000040")
get_bfile_indices(bfile)[1:5]
get_bfile_data(bfile)[1:5]

B-file Metadata and Creation

get_bfile_info() summarizes the b-file attached to a Sequence (length, first/last/min/max terms), and create_bfile() writes a vector of values out to disk in the standard b-file format:

get_bfile_info(fib)

create_bfile("A999999", data = c(1, 1, 2, 3, 5, 8), offset = 0,
             output_path = tempdir())

Citing a Sequence

get_bibtex() builds a BibTeX @misc entry for an OEIS sequence:

cat(get_bibtex(fib))

Graph Images

get_graph_png() downloads the OEIS-rendered graph image for a sequence as raw PNG bytes, cached on the Sequence object after the first call:

png_bytes <- get_graph_png(fib)

# Displays inline under Jupyter/IRkernel; otherwise returns the raw bytes
get_graph_image(fib)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.