Skip to content

Commit 82a45f0

Browse files
author
Geoffrey Hannigan
committed
Made R package.
1 parent 4dcb25f commit 82a45f0

File tree

7 files changed

+87
-0
lines changed

7 files changed

+87
-0
lines changed

DESCRIPTION

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Package: teamcolors
2+
Title: Sports Team Colors
3+
Description: Color palettes from popular sports teams.
4+
Date: 2017-02-01
5+
Version: 0.0.1
6+
Author: Geoffrey D Hannigan, PhD
7+
Maintainer: Geoffrey D Hannigan, PhD <ghannig@umich.edu>
8+
Depends:
9+
R (>= 3.0)
10+
License: Unlicense
11+
LazyData: true
12+
URL: https://github.com/Microbiology/TeamColors
13+
BugReports: https://github.com/Microbiology/TeamColors/issues
14+
RoxygenNote: 6.0.0

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(team_colors)

R/colorpal.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
load("./teamcolors.Rdata")
2+
3+
#' @title Sports team color schemes.
4+
#'
5+
#' @description These are color schemes from a variety of popular teams.
6+
#'
7+
#' @param name Name of the team to use.
8+
#' @return A vector of colors (hex format)
9+
#' @export
10+
#' @keywords colors sports
11+
#' @examples
12+
#' team_colors("Winnipeg Jets")
13+
team_colors <- function(name) {
14+
palt <- teamlist[[name]]
15+
if (is.null(palt))
16+
stop("Team colors not found!")
17+
18+
# Return the color scheme as a vector
19+
return(as.vector(palt))
20+
}

R/convertjson.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library("rjson")
2+
3+
json_file <- "https://raw.githubusercontent.com/jimniels/teamcolors/c700faa806aaa290cfd31a98225df306fda6cf14/static/data/teams.json"
4+
json_data <- fromJSON(file=json_file)
5+
6+
teamlist <- list()
7+
8+
for( i in json_data ){
9+
tname <- i$name
10+
tcol <- i$colors$hex
11+
teamlist[[ tname ]] <- tcol
12+
}
13+
14+
save(teamlist, file = "./teamcolors.Rdata")

convertjson.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
library("rjson")
2+
3+
json_file <- "https://raw.githubusercontent.com/jimniels/teamcolors/c700faa806aaa290cfd31a98225df306fda6cf14/static/data/teams.json"
4+
json_data <- fromJSON(file=json_file)
5+
6+
teamlist <- list()
7+
8+
for( i in json_data ){
9+
tname <- i$name
10+
tcol <- i$colors$hex
11+
teamlist[[ tname ]] <- tcol
12+
}
13+
14+
save(teamlist, file = "../data/teamcolors.Rdata")

man/team_colors.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

teamcolors.Rdata

2.91 KB
Binary file not shown.

0 commit comments

Comments
 (0)