Access Star Trek content from Memory Alpha.
memory_alpha(endpoint)
a data frame
The content returned is always a data frame. The structure changes slightly depending on the nature of the endpoint, but results from different endpoints can be merged easily.
At the highest level, passing endpoint = "portals"
returns a data frame
listing the available Memory Alpha portals supported by rtrek
. A column of
relative URLs is also included for reference, but can be ignored.
In all other cases, the endpoint string must begin with one of the valid
portal IDs. Passing only the ID returns a data frame with IDs and relative
URLs associated with the available categories in the specific portal. There
are two additional columns, group
and subgroup
, that may provide
additional grouping context for the entry IDs in larger tables. As with the
relative URLs, you do not have to make explicit use of these variables.
Selecting a specific category within a portal is done by appending the portal
ID in endpoint
with the category ID, separated by a forward slash. You can
append nested subcategory IDs with forward slashes, provided the
subcategories exist.
When the endpoint is neither a top-level portal or one of a portal's
categories (or subcategories, if available), it is an article. An article is
a terminal node, meaning you cannot nest further. An article will be any
entry whose URL does not begin with Category:
. In this case, the content
returned is still a data frame for consistency, but differs substantially
from the results of non-terminal endpoints.
Memory Alpha is not a database containing convenient tables. Articles
comprise the bulk of what Memory Alpha has to offer. They are not completely
unstructured text, but are loosely structured. Some assumptions are made and
memory_alpha()
returns a data frame containing article text and links. It is
up to the user what to do with this information, e.g., performing text
analyses.
The url
column included in results for context uses relative paths to save
space. The full URLs all begin the same. To visit a URL directly, prepend it
with https://memory-alpha.fandom.com/wiki/
.
Also note that once you know the relative URL for an article, e.g., "Worf"
,
you do not need to traverse through one of the portals using an endpoint
string to retrieve its content. You can instead use ma_article("Worf")
.
memory_alpha()
provides an overview perspective on how content available at
Memory Alpha is organized and can be searched for through a variety of
hierarchical layouts. And in some cases this structure that can be obtained
in table form can be useful as data or metadata in itself. Alternatively,
ma_article()
is focused exclusively on pulling back content from known
articles.
memory_alpha("portals") # show available portals
#> # A tibble: 6 × 2
#> id url
#> <chr> <chr>
#> 1 alternate Portal:Alternate_Reality
#> 2 people Portal:People
#> 3 science Portal:Science
#> 4 series Portal:TV_and_films
#> 5 society Portal:Society_and_Culture
#> 6 technology Portal:Technology
# \donttest{
memory_alpha("people") # show portal categories for People portal
#> # A tibble: 104 × 3
#> id url group
#> <chr> <chr> <chr>
#> 1 Acamarians Category:Acamarians By species
#> 2 Akritirians Category:Akritirians By species
#> 3 Aldeans Category:Aldeans By species
#> 4 Andorians Category:Andorians By species
#> 5 Androids Category:Androids By species
#> 6 Angosians Category:Angosians By species
#> 7 Aquans Category:Aquans By species
#> 8 Ardanans Category:Ardanans By species
#> 9 Augments Category:Augments By species
#> 10 Ba'ku Category:Ba%27ku By species
#> # ℹ 94 more rows
memory_alpha("people/Klingons") # show people in Klingons subcategory
#> # A tibble: 244 × 2
#> Klingons url
#> <chr> <chr>
#> 1 Memory Alpha images (Klingons) Category:Memory_Alpha_images_(Klingons)
#> 2 Amar Amar
#> 3 Antaak Antaak
#> 4 A'trom A%27trom
#> 5 Atul Atul
#> 6 Augments Category:Augments
#> 7 Azetbur Azetbur
#> 8 Ba'el Ba%27el
#> 9 Ba'ktor Ba%27ktor
#> 10 Barak-Kadan Barak-Kadan
#> # ℹ 234 more rows
memory_alpha("people/Klingons/Worf") # return terminal article content
#> # A tibble: 1 × 4
#> title content metadata categories
#> <chr> <list> <list> <list>
#> 1 Worf <xml_ndst> <tibble [1 × 16]> <tibble [14 × 2]>
# }