diff --git a/R/filter_events.R b/R/filter_events.R index 8d88dd2..e0c22c8 100644 --- a/R/filter_events.R +++ b/R/filter_events.R @@ -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 ---- diff --git a/R/get_calendar.R b/R/get_calendar.R index 940b121..4d0c0cd 100644 --- a/R/get_calendar.R +++ b/R/get_calendar.R @@ -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") diff --git a/R/get_holidays.R b/R/get_holidays.R index c0b9415..8c47e1a 100644 --- a/R/get_holidays.R +++ b/R/get_holidays.R @@ -4,7 +4,7 @@ #' Scraps the site 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'). @@ -16,8 +16,10 @@ #' @export #' #' @examples +#' \dontrun{ #' ## Get holidays for France in 2024 ---- #' get_holidays("France", 2024) +#' } get_holidays <- function(country, year) { diff --git a/R/get_month_name.R b/R/get_month_name.R index 2a9d7b5..c4b4741 100644 --- a/R/get_month_name.R +++ b/R/get_month_name.R @@ -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 ---- diff --git a/R/get_moon_phases.R b/R/get_moon_phases.R index 56ce3e6..daffb00 100644 --- a/R/get_moon_phases.R +++ b/R/get_moon_phases.R @@ -1,25 +1,34 @@ #' Get moon phases for a given year #' #' @description -#' Scraps the site to retrive moon phases data. +#' Scraps the site 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) { diff --git a/R/get_weekday_name.R b/R/get_weekday_name.R index 44dcb79..df8179d 100644 --- a/R/get_weekday_name.R +++ b/R/get_weekday_name.R @@ -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 ---- diff --git a/R/number_of_days.R b/R/number_of_days.R index 36cacea..3ee46d7 100644 --- a/R/number_of_days.R +++ b/R/number_of_days.R @@ -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) } diff --git a/R/plot_calendar.R b/R/plot_calendar.R index ade6cd3..e8e0d72 100644 --- a/R/plot_calendar.R +++ b/R/plot_calendar.R @@ -205,14 +205,43 @@ 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 ---- @@ -220,6 +249,16 @@ plot_calendar <- function(year = format(Sys.Date(), "%Y"), 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)) { diff --git a/man/get_holidays.Rd b/man/get_holidays.Rd index e2eab5a..24c29ff 100644 --- a/man/get_holidays.Rd +++ b/man/get_holidays.Rd @@ -8,7 +8,7 @@ get_holidays(country, year) } \arguments{ \item{country}{a \code{character} of length 1. The name of the country -(e.g. \code{'France'}).} +(e.g. \code{'France'}) to retrieve holidays for.} \item{year}{either an \code{integer} or a \code{character} of length 1. Must have 4 characters (e.g. '2024' and not '24').} @@ -24,6 +24,8 @@ A \code{data.frame} with the following columns: Scraps the site \url{https://www.timeanddate.com} to retrieve holidays data. } \examples{ +\dontrun{ ## Get holidays for France in 2024 ---- get_holidays("France", 2024) } +} diff --git a/man/get_moon_phases.Rd b/man/get_moon_phases.Rd index a670747..98ced14 100644 --- a/man/get_moon_phases.Rd +++ b/man/get_moon_phases.Rd @@ -14,13 +14,15 @@ characters (e.g. '2024' and not '24'). Default is the current year.} A \code{data.frame} with the following columns: \itemize{ \item \code{new_moon}: the date of new moons (\code{YYYY-MM-DD}), -\item \code{full_moon}: the date of full moons (\code{integer}). +\item \code{full_moon}: the date of full moons (\code{YYYY-MM-DD}). } } \description{ -Scraps the site \url{https://www.timeanddate.com} to retrive moon phases data. +Scraps the site \url{https://www.timeanddate.com} to retrieve moon phases data. } \examples{ +\dontrun{ ## Get moon phases for 2024 ---- get_moon_phases(2024) } +}