-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add lintr details to contributing (#58)
* add lintr details to contributing * fix linting issues
- Loading branch information
Showing
9 changed files
with
61 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(formatAY) | ||
export(roundFiveUp) | ||
export(format_ay) | ||
export(round_five_up) | ||
importFrom(lifecycle,deprecated) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
#' Format academic year | ||
#' | ||
#' This function formats academic year variables for reporting purposes. It | ||
#' will convert an academic year input from 201516 format to 2015/16 format. \cr\cr | ||
#' will convert an academic year input from 201516 format to 2015/16 format. | ||
#' | ||
#' It accepts both numerical and character arguments. | ||
#' | ||
#' @param year Academic year | ||
#' @return Character vector of formatted academic year | ||
#' @export | ||
#' @examples | ||
#' formatAY(201617) | ||
#' formatAY("201617") | ||
formatAY <- function(year) { | ||
if (!grepl("^[0-9]{6,6}$", year)) stop("year parameter must be a six digit number e.g. 201617") | ||
|
||
#' format_ay(201617) | ||
#' format_ay("201617") | ||
format_ay <- function(year) { | ||
if (!grepl("^[0-9]{6,6}$", year)) { | ||
stop("year parameter must be a six digit number e.g. 201617") | ||
} | ||
sub("(.{4})(.*)", "\\1/\\2", year) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
test_that("Rejects non 6-digit numbers", { | ||
expect_error(format_ay(19858)) | ||
expect_error(format_ay(1985)) | ||
expect_error(format_ay(1985867)) | ||
expect_error(format_ay("1999c")) | ||
expect_error(format_ay("abcdef")) | ||
expect_error(format_ay("1985-98")) | ||
}) | ||
|
||
test_that("Converts correctly", { | ||
expect_equal(format_ay(199920), "1999/20") | ||
expect_equal(format_ay("199920"), "1999/20") | ||
}) |
18 changes: 9 additions & 9 deletions
18
tests/testthat/test-roundFiveUp.R → tests/testthat/test-round_five_up.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
test_that("Rounds fives up", { | ||
expect_equal(roundFiveUp(285, -1), 290) | ||
expect_equal(roundFiveUp(2.85, 1), 2.9) | ||
expect_equal(round_five_up(285, -1), 290) | ||
expect_equal(round_five_up(2.85, 1), 2.9) | ||
}) | ||
|
||
test_that("Rounds other numbers", { | ||
expect_equal(roundFiveUp(283, -1), 280) | ||
expect_equal(roundFiveUp(2.87, 1), 2.9) | ||
expect_equal(round_five_up(283, -1), 280) | ||
expect_equal(round_five_up(2.87, 1), 2.9) | ||
}) | ||
|
||
test_that("Input validation", { | ||
expect_error( | ||
roundFiveUp("ten", "10"), | ||
round_five_up("ten", "10"), | ||
"both inputs must be numeric" | ||
) | ||
expect_error( | ||
roundFiveUp(12, "ten"), | ||
round_five_up(12, "ten"), | ||
"the decimal places value must be numeric" | ||
) | ||
expect_error( | ||
roundFiveUp(12, "10"), | ||
round_five_up(12, "10"), | ||
"the decimal places value must be numeric" | ||
) | ||
expect_error( | ||
roundFiveUp("twelve", 10), | ||
round_five_up("twelve", 10), | ||
"the value to be rounded must be numeric" | ||
) | ||
expect_error( | ||
roundFiveUp("12", 10), | ||
round_five_up("12", 10), | ||
"the value to be rounded must be numeric" | ||
) | ||
}) |