Skip to content

Commit

Permalink
Merge pull request #33 from wjakethompson/surprise-songs
Browse files Browse the repository at this point in the history
The Eras Tour Surprise Songs
  • Loading branch information
wjakethompson authored Nov 5, 2023
2 parents 1ac675f + db659f3 commit d57ef87
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,21 @@
#' @source \url{https://en.wikipedia.org/wiki/Taylor_Swift_albums_discography}
#' @source \url{https://www.metacritic.com/person/taylor-swift}
"taylor_albums"

#' The Eras Tour Surprise Songs
#'
#' A data set containing all of the surprise songs played on The Eras Tour
#' through the first North American leg of the tour.
#'
#' @format A [tibble][tibble::tibble-package] with `r nrow(eras_tour_surprise)`
#' rows and `r ncol(eras_tour_surprise)` variables:
#' * `leg`: The leg of the tour (e.g., North America, South America, etc.).
#' * `date`: The date of the show in ISO 8601 format (yyyy-mm-dd).
#' * `city`: The location of the show. For US shows, the location is the city
#' and state. For international shows, the location is the city and country.
#' * `night`: The show number within each city.
#' * `dress`: The color of the dress Taylor wore on the given night.
#' * `instrument`: The instrument used to play the song (guitar or piano).
#' * `song`: The track name of the song.
#' * `guest`: The special guest (if any) that joined Taylor to play the song.
"eras_tour_surprise"
28 changes: 28 additions & 0 deletions data-raw/surprise-songs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
library(tidyverse)
library(readxl)
library(here)

devtools::load_all()

eras_tour_surprise <- read_xlsx(here("data-raw", "surprise-songs.xlsx")) %>%
mutate(date = as_date(date),
night = as.integer(night)) %>%
filter(date < today())

# QC data file -----------------------------------------------------------------
# Check for track names are consistent. Should be 0 rows.
(bad_name <- eras_tour_surprise %>%
filter(!(song %in% taylor_all_songs$track_name)))

# Check that we're using Taylor's Version when possible. Should be 0 rows.
(not_tv <- eras_tour_surprise %>%
left_join(taylor_all_songs %>%
filter(is.na(ep) | !ep) %>%
distinct(track_name, album_name),
join_by(song == track_name),
relationship = "many-to-one") %>%
filter(!is.na(album_name),
!album_name %in% taylor_album_songs$album_name) %>%
distinct(song, album_name))

use_data(eras_tour_surprise, overwrite = TRUE)
Binary file added data-raw/surprise-songs.xlsx
Binary file not shown.
Binary file added data/eras_tour_surprise.rda
Binary file not shown.
29 changes: 29 additions & 0 deletions man/eras_tour_surprise.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ reference:
- taylor_album_songs
- taylor_all_songs
- taylor_albums
- eras_tour_surprise

- title: Plotting
- subtitle: Color palettes
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test_that("data has expected dimensions", {
# albums
expect_equal(ncol(taylor_albums), 5L)

# surprise songs
expect_equal(ncol(eras_tour_surprise), 8L)

albums <-
unique(taylor_all_songs[which((!taylor_all_songs$ep) &
!is.na(taylor_all_songs$album_name)),
Expand Down Expand Up @@ -51,6 +54,11 @@ test_that("column names match documentation expectation", {
# albums
expect_equal(colnames(taylor_albums), c("album_name", "ep", "album_release",
"metacritic_score", "user_score"))

# surprise songs
expect_equal(colnames(eras_tour_surprise), c("leg", "date", "city", "night",
"dress", "instrument", "song",
"guest"))
})

test_that("non-TV versions are excluded when possible", {
Expand All @@ -66,3 +74,13 @@ test_that("non-TV versions are excluded when possible", {

expect_false(any(exclude_albums %in% taylor_album_songs$album_name))
})

test_that("surprise songs are the correct version", {
expect_true(all(eras_tour_surprise$song %in% taylor_all_songs$track_name))

no_tv_songs <- eras_tour_surprise$song[grep("Taylor's Version",
eras_tour_surprise$song,
invert = TRUE)]
expect_false(any(paste(no_tv_songs, "(Taylor's Version)") %in%
taylor_all_songs$track_name))
})

0 comments on commit d57ef87

Please sign in to comment.