Getting Started with OEIS.R
Enrique Pérez Herrero
2026-07-19
Source:vignettes/OEIS.R-Getting-Started.Rmd
OEIS.R-Getting-Started.RmdNote: oeis.org was not reachable while
this copy of the vignette was built, so the code chunks below are shown
but were not run and display no output.
Introduction
The On-Line Encyclopedia of Integer
Sequences (OEIS) is a database of over 390,000 integer sequences,
each documented with a description, formulae, references, links, and
example code in several languages. OEIS.R fetches a
sequence’s entry from oeis.org and parses it into
structured R objects, so it can be explored, cited, and plotted without
leaving R.
Because every function in this vignette talks to
oeis.org directly (there are no bundled fixtures), building
it requires an internet connection, and the output you see reflects the
live state of OEIS at build time. Please respect OEIS’s terms of use and
avoid hammering the server with tight loops over many sequences.
OEIS urls
OEIS_web_url()
OEIS_web_url(license = TRUE)OEIS_search_url() builds a URL for a free-text search of
the encyclopedia:
OEIS_search_url("Dedekind psi function")Fetching a sequence
The OEIS_sequence S3 class
OEIS_sequence() takes an ID (a string of
the form "A" followed by 6 digits) and downloads and parses
the sequence’s full entry:
id <- "A001615"
A001615 <- OEIS_sequence(id)
class(A001615)
names(A001615)An invalid ID is rejected up front, before any network
request is made:
OEIS_check("hello")Basic sequence information
A001615$ID
A001615$description
A001615$formerly # old M-/N-number from Sloane's printed catalogs
A001615$offset
A001615$keywords
A001615$status
A001615$urlAuthor and date
A001615$authorNot every entry has a parseable trailing date on its author line —
when it doesn’t, $date is NULL rather than a
Date:
A001615$date
A138240 <- OEIS_sequence("A138240")
A138240$dateTerms
$terms holds the (typically 50-80) leading terms shown
on the sequence’s page:
head(A001615$terms, 15)For longer runs, use the sequence’s b-file, which
OEIS provides separately and which this package downloads via
OEIS_bfile():
A001615$bfile$min_n
A001615$bfile$max_n
head(A001615$bfile$data)Comments, formula, and links
library(knitr)
kable(data.frame(link = A001615$links[1:5]))Cross references
Besides the sequences explicitly referenced in the entry’s
CROSSREFS section ($cf), OEIS also shows the
neighboring sequences in lexicographic order
($seqs_in_context) and by A-number
($seqs_adjacent):
A001615$crossrefs$cf
A001615$crossrefs$seqs_in_context
A001615$crossrefs$seqs_adjacentPlotting
Base R
plot(A001615)
ggplot2
OEIS_ggplot() plots the full b-file (not just the
leading terms shown above) and returns a normal ggplot
object you can extend:
library(ggplot2)
OEIS_ggplot(A001615) +
geom_line() +
geom_point(size = 0.5, color = "green") +
labs(title = paste("OEIS", id, "-", A001615$description))Citing a sequence
OEIS_bibtex() builds a citable bibentry for
a sequence, following the citation format suggested by OEIS itself:
bref <- OEIS_bibtex(A001615)
print(bref, style = "Bibtex")
bref$noteWorking from just an ID
Every accessor used above (OEIS_description(),
OEIS_formula(), …) also works directly on a character
ID, without building the full OEIS_sequence
object first — useful when you only need one or two fields and want to
avoid the extra requests OEIS_sequence() makes (crossrefs
and b-file, in particular, each cost a separate request):
OEIS_description(id)
OEIS_keywords(id)Internally, a character ID is validated into an
OEIS_ID object and then, for most fields, converted to the
sequence’s parsed internal format (OEIS’s compact
%-tagged export format). You can inspect that intermediate
object directly:
internal_format <- OEIS_internal_format(id)
class(internal_format)
head(internal_format)