-
Notifications
You must be signed in to change notification settings - Fork 1
/
logo.R
63 lines (51 loc) · 2.16 KB
/
logo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#' @template make-logo
#' @export
make_logo <- function(template = "./inst/assets/logo/parabar-logo.txt", version = c(1, 0, 0)) {
# Load the ASCII logo.
logo <- readLines(template)
# Create a text connection.
connection <- textConnection(NULL, open = "w", local = TRUE)
# Close the connection on exit.
on.exit({
# Close.
close(connection)
})
# Redirect console output.
sink(connection, type = "output")
# Parse the logo.
logo <- dput(logo)
# Remove output redirection.
sink(NULL)
# Update versioning.
logo <- gsub("{{major}}", version[1], logo, perl = TRUE)
logo <- gsub("{{minor}}", version[2], logo, perl = TRUE)
logo <- gsub("{{patch}}", version[3], logo, perl = TRUE)
# Condensed version.
logo <- paste(logo, collapse = "\n")
return(logo)
}
#' @title
#' The Package Logo
#'
#' @description
#' The logo is generated by [parabar::make_logo()] and displayed on package
#' attach for interactive `R` sessions.
#'
#' @format
#' An object of class `character` containing the `ASCII` logo.
#'
#' @examples
#' print(LOGO)
#'
#' @seealso [parabar::make_logo()]
#'
#' @export
LOGO = ". . . . . . . . . . . . . . . . . . . . . . . . . . .\n. _ v1.x.x .\n. | | .\n. _ __ __ _ _ __ __ _ | |__ __ _ _ __ .\n. | '_ \\ / _` || '__| / _` || '_ \\ / _` || '__| .\n. | |_) || (_| || | | (_| || |_) || (_| || | .\n. | .__/ \\____||_| \\____||____/ \\____||_| .\n. | | .\n. |_| .\n. .\n. . . . . . . . . . . . . . . . . . . . . . . . . . .\n. . .\n. https://parabar.mihaiconstantin.com .\n. . .\n. . . . . . . . . . . . . . . . . . . . . . . . . . ."
# Add package logo class.
class(LOGO) <- "parabar"
# Add S3 method for properly printing the logo.
#' @export
print.parabar <- function(x, ...) {
# Print the logo.
cat(LOGO, sep = "")
}