Learn R Programming

⚠️There's a newer version (0.14.2) of this package.Take me there.

SwimmeR

SwimmeR is intended to assist those working with times from competitive pool swimming races, such as those conducted under the NHFS, NCAA, or FINA. For more information please see vignette("SwimmeR").

Latest Released Version from CRAN

install.packages("SwimmeR")

library(SwimmeR)

Latest Development Version from Github

devtools::install_github("gpilgrim2670/SwimmeR", build_vignettes = TRUE)

library(SwimmeR)

Usage

Version 0.3.0 of SwimmeR has two major uses - importing results and formatting times.

Importing Results

SwimmeR reads swimming results into R and outputs tidy dataframes of the results. SwimmeR uses Read_Result to read in either a PDF or HTML file (like a url) and the Swim_Parse to convert the read file to a tidy dataframe.

Read_Result has two arguments, file, which is the file path to read in, and node, required only for HTML files, this is a CSS node where the results reside

Swim_Parse has four arguments. file is the output of Read_Result and is required. avoid is a list of strings. Rows of the read in file containing any of those strings will not be included. avoid is optional. Incorrectly specifying it may lead to nonsense rows in the final dataframe, but will not cause an error. typo and replacement work together to fix typos, by replacing them with replacements. Strings in typo will be replaced by strings in replacement in element index order - that is the first element of typo will be replaced everywhere it appears by the first element of replacement. Typos can cause lost data and nonsense rows. See ?Swim_Parse or the package vignette for more information.

Swim_Parse(
    Read_Results(
      "http://www.nyhsswim.com/Results/Boys/2008/NYS/Single.htm",
      node = "pre"
    ),
    typo = c("-1NORTH ROCKL"),
    replacement = c("1-NORTH ROCKL")
  )

SwimmeR can only read files in single column format, not double. SwimmeR also does not capture split times.

Will not work

Will work

Will also work

Formatting Times

SwimmeR also converts times between the conventional swimming format of minutes:seconds.hundredths (1:35.37) and the computationally useful format of seconds, reported to the 100ths place (e.g. 95.37). This is accomplished with sec_format and mmss_format, which are inverses of one another. Both sec_format and mmss_format work well with tidyverse functions.

times <- c("1:35.97", "57.34", "16:53.19", NA)
times_sec <- sec_format(times)
times_sec
times_mmss <- mmss_format(times_sec)
times_mmss
all.equal(times, times_mmss)

Regularizing team names

Team names are often abbreviated. Rather than specifying every abbreviation SwimmeR provides get_mode to make the task simpler.

Name <- c(rep("Lilly King", 5), rep("James Sullivan", 3))
Team <- c(rep("IU", 2), "Indiana", "IUWSD", "Indiana University", rep("Monsters University", 2), "MU")
df <- data.frame(Name, Team, stringsAsFactors = FALSE)
df %>% 
  group_by(Name) %>% 
  mutate(Team = get_mode(Team))

Drawing brackets

Brackets for single elimination tournaments can be produced for any number of teams between 5 and 64. Byes will automatically be included for higher seeds as required.

teams <- c("red", "orange", "yellow", "green", "blue", "indigo", "violet")
round_two <- c("red", "yellow", "blue", "indigo")
round_three <- c("red", "blue")
champion <- "red"
draw_bracket(teams = teams,
            round_two = round_two,
            round_three = round_three,
            champion = champion)

Course conversions

Additionally 'SwimmeR' also converts between the various pool sizes used in competitive swimming, namely 50m length (LCM), 25m length (SCM) and 25y length (SCY). This is accomplished with either convert_courses or convert_courses_DF, both of which have the same basic functionality. The difference is the convert_courses_DF returns a dataframe including the input variables whereas convet_courses only returns the converted time(s). Both functions will take inputs in either seconds or swimming format.

Swim <- tibble(time = c("6:17.53", "59.14", "4:14.32", "16:43.19"), course = c("LCM", "LCM", "SCY", "SCM"), course_to = c("SCY", "SCY", "SCM", "LCM"), event = c("400 Free", "100 Fly", "400 IM", "1650 Free"))

course_convert(time = Swim$time, course = Swim$course, course_to = Swim$course_to, event = Swim$event)

course_convert_DF(time = Swim$time, course = Swim$course, course_to = Swim$course_to, event = Swim$event)

Getting help

For more information please see vignette("SwimmeR"). If you download from github don't forget to set build_vignettes = TRUE.

If you find bug, please provide a minimal reproducible example at github.

Copy Link

Version

Install

install.packages('SwimmeR')

Monthly Downloads

339

Version

0.3.0

License

MIT + file LICENSE

Maintainer

Greg Pilgrim

Last Published

July 10th, 2020

Functions in SwimmeR (0.3.0)

course_convert

Swimming Course Convertor
sec_format

Formatting mm:ss.tt times as seconds
%>%

Pipe operator
course_convert_DF

Course converter, returns dataframe
Swim_Parse

Formats swimming and diving data read in with Read_Results into dataframe
King200Breast

Results for Lilly King's 200 Breastsrokes
Read_Results

Reads swimming and diving results into a list of strings in preparation for parsing with Swim_Parse
get_mode

Find the mode (most commonly occurring) element of a list
draw_bracket

Creates a bracket for tournaments involving 5 to 64 teams, single elimination
SwimmeR

SwimmeR: A package for working with swimming times
sec_format_helper

Helper function for formatting mm:ss.hh times as seconds
mmss_format

Formatting seconds as mm:ss.hh
fold

Fold a vector onto itself