-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from serkor1/master
Issue #57 fix 🔧
- Loading branch information
Showing
8 changed files
with
248 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ | |
^NEWS\.md$ | ||
^\.github$ | ||
^pkgdown$ | ||
^sandbox |
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 @@ | ||
Package: calendar | ||
Title: Create, Read, Write, and Work with 'iCalander' Files, Calendars and | ||
Title: Create, Read, Write, and Work with 'iCalendar' Files, Calendars and | ||
Scheduling Data | ||
Version: 0.1.0 | ||
Authors@R: | ||
|
@@ -22,9 +22,15 @@ Authors@R: | |
family = "Scarafia", | ||
role = "ctb", | ||
email = "[email protected]", | ||
comment = c(ORCID = "0009-0005-9822-169X"))) | ||
comment = c(ORCID = "0009-0005-9822-169X")), | ||
person(given = "Serkan", | ||
family = "Korkmaz", | ||
email = "[email protected]", | ||
role = c("ctb"), | ||
comment = c(ORCID = "0000-0002-5052-0982")) | ||
) | ||
Description: Provides function to create, read, write, and work with | ||
'iCalander' files (which typically have '.ics' or '.ical' extensions), | ||
'iCalendar' files (which typically have '.ics' or '.ical' extensions), | ||
and the scheduling data, calendars and timelines of people, | ||
organisations and other entities that they represent. 'iCalendar' is | ||
an open standard for exchanging calendar and scheduling information | ||
|
@@ -35,8 +41,8 @@ BugReports: https://github.com/ATFutures/calendar/issues | |
Depends: | ||
R (>= 3.4.0) | ||
Imports: | ||
cli, | ||
lubridate, | ||
methods, | ||
tibble | ||
Suggests: | ||
covr, | ||
|
@@ -48,4 +54,4 @@ VignetteBuilder: | |
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.1 | ||
RoxygenNote: 7.3.1 |
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
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,111 @@ | ||
# script: Utilities | ||
# author: Serkan Korkmaz, [email protected] | ||
# date: 2024-08-09 | ||
# objective: Generate a set of utility functions | ||
# to reduce repeated coding, and simple tasks. | ||
# script start; | ||
|
||
#' Assert truthfulness of conditions before evaluation | ||
#' | ||
#' @description | ||
#' This function is a wrapper of [stopifnot()], [tryCatch()] and | ||
#' [cli::cli_abort()] and asserts the truthfulness of the passed expression(s). | ||
#' @param ... expressions >= 1. If named the names are used | ||
#' as error messages, otherwise R's internal error-messages are thrown | ||
#' | ||
#' @param error_message character. An error message, supports [cli]-formatting. | ||
#' @seealso [stopifnot()], [cli::cli_abort()], [tryCatch()] | ||
#' @keywords internal | ||
#' | ||
#' @returns [NULL] if all statements in ... are [TRUE] | ||
assert <- function( | ||
..., | ||
error_message = NULL) { | ||
|
||
# 1) count number of expressions | ||
# in the ellipsis - this | ||
# is the basis for the error-handling | ||
number_expressions <- ...length() | ||
named_expressions <- ...names() | ||
|
||
|
||
# 2) if there is more than | ||
# one expression the condtions | ||
# will either be stored in an list | ||
# or pased directly into the tryCatch/stopifnot | ||
if (number_expressions != 1 & !is.null(named_expressions)){ | ||
|
||
# 2.1) store all conditions | ||
# in a list alongside its | ||
# names | ||
conditions <- c(...) | ||
|
||
# 2.2) if !is.null(condition_names) the | ||
# above condition never gets evaluated and | ||
# stopped otherwise, if there is errors | ||
# | ||
# The condition is the names(list()), and is | ||
# the error messages written on lhs of the the assert | ||
# function | ||
if (all(conditions)) { | ||
|
||
# Stop the funciton | ||
# here if all conditions | ||
# are [TRUE] | ||
return(NULL) | ||
|
||
} else { | ||
|
||
cli::cli_abort( | ||
message = c( | ||
"x" = named_expressions[which.min(conditions)] | ||
), | ||
call = sys.call( | ||
1 - length(sys.calls()) | ||
) | ||
) | ||
|
||
} | ||
|
||
} | ||
|
||
# 3) if there length(...) == 1 then | ||
# above will not run, and stopped if anything | ||
|
||
tryCatch( | ||
expr = { | ||
eval.parent( | ||
substitute( | ||
stopifnot(exprs = ...) | ||
) | ||
) | ||
}, | ||
error = function(error){ | ||
|
||
# each error message | ||
# has a message and call | ||
# | ||
# the call will reference the caller | ||
# by default, so we need the second | ||
# topmost caller | ||
|
||
cli::cli_abort( | ||
# 3.1) if the length of expressions | ||
# is >1, then then the error message | ||
# is forced to be the internal otherwise | ||
# the assert function will throw the same error-message | ||
# for any error. | ||
message = if (is.null(error_message) || number_expressions != 1) | ||
error$message else | ||
error_message, | ||
call = sys.call( | ||
1 - length(sys.calls()) | ||
) | ||
) | ||
|
||
} | ||
) | ||
|
||
} | ||
|
||
# script end; |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.