In class we developed the package gameday
and showed how to
devtools::create()
DESCRIPTION
fileroxygen2
comments and devtools::document()
Imports
field of DESCRIPTION
and syntax like foopkg::foofunction()
devtools::load_all()
devtools::use_vignette()
and devtools::build_vignettes()
testthat
for unit testing with devtools::use_testthat()
and run your tests with devtools::test()
devtools::install_github()
worksThe landing page for all the package material contains lots of links with extra technical information and general inspiration.
In this homework you will either continue developing the gameday
package or create your own package (inspiration given below).
Below we outline follow-up tasks for gameday
. If you develop your own package, it must include the following elements:
?
@param
, @return
, @examples
, at least.Error: could not find function
testthat
for your testing.assertthat
for this validity check and import the assertthat
package correctly, as we did for RCurl
testthat::expect_error()
.devtools::check()
without errors (warnings and notes are OK).README.md
that shows how to install your package, a minimal example how it works, and links to the vignette. (If you are uncomfortable making your homework public to the world please contact Jenny and we can find a way around that. This may require some fiddling but is doable.)Submit an issue with a link to your package sometime on Friday November 21 if you need the weekend, submit before class on Monday November 24.
gameday
as it should have been at the end of class from Bernhard’s Github. Use your mad Git skilz to get it or simply unzip this file.The only difference from the class activity is that this version is a better R citizen with respect to namespace and imports. The RCurl
dependency has been moved from Depends
to Imports
and we call getURL()
like so: RCurl::getURL
. Go here for more explanation on this detail.
If you don’t feel like developing your own package, here’s a gameday
blueprint that is a respectable way to complete the assignment. You are welcome to remix R code already written by someone, student or JB, in this class, but credit/link appropriately, e.g. in comments or your vignette. Take full advantage of office hours and the Discussion board!
If you can’t do all of this, do what you can. Make sure to include the vignette and push to GitHub, since that is needed for peer review and marking. Jenny took a crack at some parts of this homework and has some hints.
team.name
to team
and provide the default value "canucks"
. Update the documentation, examples and tests accordingly.Add a second argument date
that defaults to Sys.Date()
and gives the user the option to see whether their team plays or played on a particular day. Include this test of the new date functionality:
test_that("Vancouver Canucks had a game against Nashville Predators on 2014-11-02", {
expect_true(gday(team = "canucks", date = "2014-11-02"))
expect_true(gday(team = "predators", date = "2014-11-02"))
})
expect_false()
to develop a similar test that a certain team did not have a game on a certain day.Kill your internet connection and use gday()
. What happens? Make this failure more graceful and informative for the user. To help with this, we’ll add a helper function internet_connection()
that takes no argument. This function should NOT be exported, that is, it should not be callable directly when gameday
is loaded. The internet_connection()
function below returns a logical that is only TRUE
if an internet connection can be established:
internet_connection <- function() {
tryCatch({RCurl::getURL("www.google.com"); TRUE},
error = function(err) FALSE)
}
Use this helper function in gday()
to check for an internet connection before trying to get info from the web. If there is is no internet connection, explain this failure to the user.check_date()
that performs a validity check on argument date
and returns a logical that is only TRUE
when date
is a valid date. You can check the value of as.Date(date)
for that. Add at least one expect_true()
and expect_false()
test for check_date
.check_date()
to throw an error in gday()
if the provided date does not have the right format. A date like 201-411-07
should throw an error early. Use assertthat
to throw the error. This requires that the assertthat
package is imported (copy what we did for RCurl
). Then add a test with testthat::expect_error()
to confirm that invalid date input triggers the error.Add another function scores()
that takes date
and returns a data.frame with information about the games on date
. Use your helper functions to confirm an internet connection and a valid date. The R code below can be used as fodder for your function.
url <- paste0('http://live.nhle.com/GameData/GCScoreboard/',
date, '.jsonp')
raw <- RCurl::getURL(url)
json <- gsub('([a-zA-Z_0-9\\.]*\\()|(\\);?$)', "", raw, perl = TRUE)
data <- jsonlite::fromJSON(json)$games
with(data,
data.frame(home = paste(htn, htcommon),
away = paste(atn, atcommon),
home_score = hts,
away_score = ats))
scores()
so that the user can access it when gameday
is loaded. Also add a documentation that provides @param
, @return
and @examples
. Then add a handful of tests.gday
or scores
can be used to gain some insight. For example, to list all winning teams of a certain hockey day (you can use friends like dplyr
or ggplot
if you want to be fancy).Finally, update the Version number to 1.0.0
and upload your package to a public repository on GitHub. Add a minimal README.md
that explains how to install your package, a minimal example how it works, and points to the vignette. (If you are uncomfortable making your homework public to the world please contact Jenny and we can find a way around that. This may require some fiddling but is doable.)
testthat::context(...)
to separate your tests into logical chunks.scores
returns by capturing more fields. Depending on what you want to do this may call for more helper functions or more functions that are exported. Document your new functions, add tests, and extend the vignette. Below is a description of what fields are available in the data.field datatype description
ata char(3) Away team acronym, 3 letter short name
atc text Before: blank During: "progress" After: "winner" if away team wins
atcommon text away team common name
atn text away team city name
ats int away team score
atsog int Before: null During and After: away team shots on goal
bs time/text Before: start time (unsure if local or EST) During: 05:10 2nd, eg After: "FINAL", "FINAL OT" etc
bsc text Before: blank During: "progress" After: "final"
canationalbroadcasts text Canadian TV broadcasters, comma separated list
gcl Bool gamecenter live?
gcll bool gamecenter live?
gs int game status? 1=scheduled, 3= in progress, 5=finished
hta char(3) home team acronym
htc text Before: blank During: "progress" After: "winner" if home team wins
htcommon text home team common name
htn text home team city name
hts int home team score
htsog int Before: null During and After: home team shots on goal
id int game ID
rl Bool true after game completed
usnationalbroadcasts text US tv broadcasters, comma separated list
data
directory that provides a data.frame of all team names with the corresponding city and name of their home arena. Do not read this data from the web, you can download this data file here. Here is a short intro on how to add data to your R package.team
in the function gday()
. Return an error if this team is not listed in the data.frame (that is, if the city does not have an NHL team or if the team name has a typo). Write a test that triggers this error with testthat::expect_error()
.gday()
so that it works if the user requests info for the “Canucks” or “Vancouver.”Do you want to write your very own package and ditch gameday
? Here are some ideas.
cats
with your favorite animal.peek()
: kind of like head()
and tail()
but uses a random sample instead of the first few or last elementswrite.table()
that, by default, sets row.names = FALSE
, quote = FALSE
and sep =
to tab or commaNA
sleuth to provide a report and perhaps visual info on how many NA
s are in a data.frame, afflicting which variables, in which rowsfactorboss
desc()
a la (d)plyr
factor()
that sets levels to the order in which they appear in the data, i.e. set the levels “as is”Your peer reviewer will try to install your package from GitHub and use it! They will follow your instructions from README.md
and might even try stuff from your vignette.
Check minus: Package does not install. Or installation seemed go OK but one or more of the functions don’t work. Or you do something that seems totally natural (probably copied from README.md
or vignette) and get odd behavior.
Check: Hits most/all the elements. No obvious technical difficulties. Package pleasant to use. README.md
and vignette are pleasant to read and provide accessible examples of usage. No heroic detective work required. Good work!
Check plus: Exceeded the requirements in number of dimensions. Took gameday
farther than was required. Wrote a new package from scratch. Experience of installation and usage was dreamy because of excellent documentation and high functionality. You learned something new from reviewing their work and you’re eager to incorporate it into your work. Wow!
Recall the general homework rubric.