Skip to content

Commit

Permalink
doc: add checks & fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Mar 31, 2024
1 parent 229dcc5 commit c98eaac
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 12 deletions.
18 changes: 18 additions & 0 deletions R/filter_events.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ filter_events <- function(data, year = format(Sys.Date(), "%Y"),
"information", call. = FALSE)
}

if (!is.character(format)) {
stop("Argument 'format' must be a character", call. = FALSE)
}

if (length(format) != 1) {
stop("Argument 'format' must be of length 1", call. = FALSE)
}

if (!is.logical(weekend)) {
stop("Argument 'weekend' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}

if (length(weekend) != 1) {
stop("Argument 'weekend' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}


## Filter event dates ----

Expand Down
21 changes: 21 additions & 0 deletions R/get_calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ get_calendar <- function(year = format(Sys.Date(), "%Y"),
call. = FALSE)
}

if (!is.logical(weekend)) {
stop("Argument 'weekend' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}

if (length(weekend) != 1) {
stop("Argument 'weekend' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}

if (!is.null(lang)) {
if (!is.character(lang)) {
stop("Argument 'lang' must be a character", call. = FALSE)
}

if (length(lang) != 1) {
stop("Argument 'lang' must be of length 1", call. = FALSE)
}
}


## Switch to US locale ----

lc_time <- Sys.getlocale("LC_TIME")
Expand Down
4 changes: 3 additions & 1 deletion R/get_holidays.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' Scraps the site <https://www.timeanddate.com> to retrieve holidays data.
#'
#' @param country a `character` of length 1. The name of the country
#' (e.g. `'France'`).
#' (e.g. `'France'`) to retrieve holidays for.
#'
#' @param year either an `integer` or a `character` of length 1. Must have 4
#' characters (e.g. '2024' and not '24').
Expand All @@ -16,8 +16,10 @@
#' @export
#'
#' @examples
#' \dontrun{
#' ## Get holidays for France in 2024 ----
#' get_holidays("France", 2024)
#' }

get_holidays <- function(country, year) {

Expand Down
10 changes: 10 additions & 0 deletions R/get_month_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ get_month_name <- function(month, lang = NULL) {
stop("Argument 'month' must be between 1 and 12", call. = FALSE)
}

if (!is.null(lang)) {
if (!is.character(lang)) {
stop("Argument 'lang' must be a character", call. = FALSE)
}

if (length(lang) != 1) {
stop("Argument 'lang' must be of length 1", call. = FALSE)
}
}


## Switch locale ----

Expand Down
15 changes: 12 additions & 3 deletions R/get_moon_phases.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
#' Get moon phases for a given year
#'
#' @description
#' Scraps the site <https://www.timeanddate.com> to retrive moon phases data.
#' Scraps the site <https://www.timeanddate.com> to retrieve moon phases data.
#'
#' @param year either an `integer` or a `character` of length 1. Must have 4
#' characters (e.g. '2024' and not '24'). Default is the current year.
#'
#' @return A `data.frame` with the following columns:
#' - `new_moon`: the date of new moons (`YYYY-MM-DD`),
#' - `full_moon`: the date of full moons (`integer`).
#' - `full_moon`: the date of full moons (`YYYY-MM-DD`).
#'
#' @export
#'
#' @examples
#' \dontrun{
#' ## Get moon phases for 2024 ----
#' get_moon_phases(2024)
#' }

get_moon_phases <- function(year) {

## Check args ----

if (missing(year)) {
stop("Argument 'year' is required", call. = FALSE)
}

if (!is.character(year) && !is.numeric(year)) {
stop("Argument 'year' must either a character or an integer", call. = FALSE)
stop("Argument 'year' must be either a character or an integer",
call. = FALSE)
}

if (length(year) > 1) {
Expand Down
18 changes: 18 additions & 0 deletions R/get_weekday_name.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ get_weekday_name <- function(date, format = "%Y-%m-%d", lang = NULL) {
"information", call. = FALSE)
}

if (!is.character(format)) {
stop("Argument 'format' must be a character", call. = FALSE)
}

if (length(format) != 1) {
stop("Argument 'format' must be of length 1", call. = FALSE)
}

if (!is.null(lang)) {
if (!is.character(lang)) {
stop("Argument 'lang' must be a character", call. = FALSE)
}

if (length(lang) != 1) {
stop("Argument 'lang' must be of length 1", call. = FALSE)
}
}


## Switch locale ----

Expand Down
2 changes: 2 additions & 0 deletions R/number_of_days.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

number_of_days <- function(date, format = "%Y-%m-%d") {

## Check args ----

if (missing(date)) {
stop("Argument 'date' is required", call. = FALSE)
}
Expand Down
49 changes: 44 additions & 5 deletions R/plot_calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,60 @@ plot_calendar <- function(year = format(Sys.Date(), "%Y"),
}


## Create filename ----
## Check moon ----

if (is.null(filename)) {
filename <- paste("calendar", year, month, sep = "-")
if (!is.logical(moon)) {
stop("Argument 'moon' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}

if (length(moon) != 1) {
stop("Argument 'moon' must be a logical ('TRUE' or 'FALSE')",
call. = FALSE)
}


## Check lang ----

if (!is.null(lang)) {
if (!is.character(lang)) {
stop("Argument 'lang' must be a character", call. = FALSE)
}

if (length(lang) != 1) {
stop("Argument 'lang' must be of length 1", call. = FALSE)
}
}

filename <- paste0(filename, ".pdf")
filename <- gsub("\\.pdf\\.pdf", ".pdf", filename)

## Check country ----

if (!is.null(country)) {
if (!is.character(country)) {
stop("Argument 'country' must be a character", call. = FALSE)
}

if (length(country) != 1) {
stop("Argument 'country' must be of length 1", call. = FALSE)
}
}


## Get calendar data ----

calendar <- get_calendar(year, month, weekend, lang = lang)


## Create file name ----

if (is.null(filename)) {
filename <- paste("calendar", year, month, sep = "-")
}

filename <- paste0(filename, ".pdf")
filename <- gsub("\\.pdf\\.pdf", ".pdf", filename)


## Create title ----

if (is.null(title)) {
Expand Down
4 changes: 3 additions & 1 deletion man/get_holidays.Rd

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

6 changes: 4 additions & 2 deletions man/get_moon_phases.Rd

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

0 comments on commit c98eaac

Please sign in to comment.