SpaceX - An R API wrapper for the SpaceX project

December 30, 2020 · View on GitHub

Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.

Installation

Until now the package is not on CRAN but you can download it via GitHub with the following command:

if (!require("devtools"))
  install.packages("devtools")
devtools::install_github("JohannesFriedrich/SpaceX")

Introduction

The R-package SpaceX is an API wrapper for data collected by https://api.spacexdata.com/v3/ (version v3). You can request available data with different functions:

Function nameDescriptionExample
get_SpaceX_capsules()request information on capsulesget_SpaceX_capsules(“upcoming”)
get_SpaceX_cores()request information on coresget_SpaceX_cores(core_serial = “B1037”)
get_SpaceX_dragons()request information on dragon capsulesget_SpaceX_dragons(“dragon1”)
get_SpaceX_history()request information on SpaceX historyget_SpaceX_history()
get_SpaceX_info()request common information on SpaceXget_SpaceX_info()
get_SpaceX_landpads()request information on landpadsget_SpaceX_landpads(id = “LZ-4”)
get_SpaceX_launches()request information on launchesget_SpaceX_launches(launch_year = 2020)
get_SpaceX_launchpads()request information on launchpadsget_SpaceX_launchpads(site_id = “ksc_lc_39a”)
get_SpaceX_missions()request information on missionsget_SpaceX_missions()
get_SpaceX_payloads()request information on payloadsget_SpaceX_payloads()
get_SpaceX_rockets()request information on rocketsget_SpaceX_rockets(“falcon1”)
get_SpaceX_ships()request information on shipsget_SpaceX_ships()
get_SpaceX_roadster()request information on SpaceX roadsterget_SpaceX_roadster()

Request basic information from SpaceX API

First we load some needed packages. The function get_SpaceX_info() will deliver some information about the company.

library(SpaceX)
library(ggplot2)
library(dplyr)

info <- get_SpaceX_info()
name founder founded employees vehicles launch\_sites test\_sites
SpaceX Elon Musk 2002 7000 3 3 1

Request upcoming starts

upcoming <- get_SpaceX_launches("upcoming")
flight\_number mission\_name mission\_id launch\_year launch\_date\_unix launch\_date\_utc launch\_date\_local is\_tentative tentative\_max\_precision
1 110 CRS-21 EE86F74 2020 1607271420 2020-12-06T16:17:00.000Z 2020-12-06T11:17:00-05:00 FALSE hour
2 110 SXM-7 2020 1607880600 2020-12-13T17:30:00.000Z 2020-12-13T12:30:00-05:00 FALSE hour
NA NA NA NULL NA NA NA NA NA NA

Play around with data

get_SpaceX_launches() %>% 
ggplot() + 
  geom_bar(aes(launch_year, fill = launch_site$site_name)) +
  facet_grid(rocket$rocket_name~launch_success, scales = "free_x") +
  theme(legend.position = "bottom") + 
  scale_fill_discrete(name = "Launch Site") +
  labs(x = "Year", y = "Counts") +
  theme(legend.position = "bottom",
        axis.text.x = element_text(angle = 45, hjust = 1))

Now we request some data about the used rockets. This can be done with the function get_SpaceX_rockets().

rockets <- get_SpaceX_rockets()
id active stages boosters cost\_per\_launch success\_rate\_pct first\_flight country company
1 FALSE 2 0 6.7e+06 40 2006-03-24 Republic of the Marshall Islands SpaceX
2 TRUE 2 0 5.0e+07 97 2010-06-04 United States SpaceX
3 TRUE 2 2 9.0e+07 100 2018-02-06 United States SpaceX
4 FALSE 2 0 7.0e+06 0 2021-12-01 United States SpaceX

Stats 2020

stats_2020 <- get_SpaceX_launches(launch_year = 2020)
launchpads <- get_SpaceX_launchpads()
  
library(leaflet)
library(htmltools)

leaflet(launchpads) %>%
  addProviderTiles(providers$OpenStreetMap) %>% 
  addTiles() %>%  
  addMarkers(~location$long, ~location$lat, popup = ~htmltools::htmlEscape(location$name))

Missions

missions <- get_SpaceX_missions()
mission\_name mission\_id manufacturers
Thaicom 9D1B7E0 Orbital ATK
Telstar F4F83DE SSL
Iridium NEXT F3364BF Orbital ATK
Commercial Resupply Services EE86F74 SpaceX
SES 6C42550 Orbital ATK , Boeing , Airbus Defence and Space
JCSAT FE3533D SSL
AsiaSat 593B499 SSL
Orbcomm OG2 CE91D46 Sierra Nevada Corporation
ABS 2CF444A Boeing
Eutelsat F7709F2 Boeing

SpaceX support ships

ship <- get_SpaceX_ships(active = "true")
ship\_id ship\_name ship\_model ship\_type roles active imo
GOMSCHIEF GO Ms Chief NA High Speed Craft Fairing Recovery TRUE 9744453
GOMSTREE GO Ms Tree NA High Speed Craft Fairing Recovery TRUE 9744465
GONAVIGATOR GO Navigator NA Cargo Support Ship , Fairing Recovery TRUE 9566887
GOQUEST GO Quest NA Cargo Support Ship TRUE 1155515