Skip to content

Commit

Permalink
fix: add sticker to compendium - fix #54
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasverus committed Oct 26, 2023
1 parent fc73f55 commit f280e36
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion R/new_compendium.R
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ new_compendium <- function(compendium = NULL, license = "GPL (>= 2)",
add_readme_rmd(type = "compendium", given, family, organisation,
open = FALSE, overwrite = overwrite, quiet = quiet)

# add_sticker(overwrite = overwrite, quiet = quiet)
add_sticker(type = "compendium", overwrite = overwrite, quiet = quiet)



Expand Down
2 changes: 1 addition & 1 deletion R/new_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ new_package <- function(license = "GPL (>= 2)", status = NULL,
add_readme_rmd(type = "package", given, family, organisation, open = FALSE,
overwrite = overwrite, quiet = quiet)

add_sticker(overwrite = overwrite, quiet = quiet)
add_sticker(type = "package", overwrite = overwrite, quiet = quiet)



Expand Down
74 changes: 47 additions & 27 deletions R/utils-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,34 @@ add_badge <- function(badge, pattern) {
#'
#' @noRd

add_sticker <- function(overwrite = FALSE, quiet = FALSE) {
add_sticker <- function(type, overwrite = FALSE, quiet = FALSE) {

if (missing(type)) {
stop("Argument 'type' is required.")
}

if (is.null(type)) {
stop("Argument 'type' must be 'package' or 'compendium'.")
}

if (length(type) != 1) {
stop("Argument 'type' must be 'package' or 'compendium'.")
}

if (!(tolower(type) %in% c("package", "compendium"))) {
stop("Argument 'type' must be 'package' or 'compendium'.")
}

type <- tolower(type)

stop_if_not_logical(overwrite, quiet)

path <- file.path(path_proj(), "man", "figures", "package-sticker.png")
path <- file.path(path_proj(), "man", "figures", paste0(type, "-sticker.png"))

if (file.exists(path) && !overwrite) {

stop("A 'man/figures/package-sticker.png' is already present. If you want ",
"to replace it, please use `overwrite = TRUE`.")
stop(paste0("A 'man/figures/", type, "-sticker.png' is already present. ",
"If you want to replace it, please use `overwrite = TRUE`."))
}


Expand All @@ -168,33 +185,36 @@ add_sticker <- function(overwrite = FALSE, quiet = FALSE) {
recursive = TRUE)

invisible(
file.copy(system.file(file.path("templates", "package-sticker.png"),
file.copy(system.file(file.path("templates", paste0(type, "-sticker.png")),
package = "rcompendium"), path, overwrite = TRUE))


if (!dir.exists(file.path(path_proj(), "inst", "package-sticker")))
dir.create(file.path(path_proj(), "inst", "package-sticker"),
showWarnings = FALSE, recursive = TRUE)


path <- file.path(path_proj(), "inst", "package-sticker", "r_logo.png")

if (!file.exists(path)) {
invisible(
file.copy(system.file(file.path("templates", "r_logo.png"),
package = "rcompendium"), path, overwrite = FALSE))
}


path <- file.path(path_proj(), "inst", "package-sticker", "package-sticker.R")

if (!file.exists(path)) {
invisible(
file.copy(system.file(file.path("templates", "package-sticker.R"),
package = "rcompendium"), path, overwrite = FALSE))
if (type == "package") {

if (!dir.exists(file.path(path_proj(), "inst", "package-sticker")))
dir.create(file.path(path_proj(), "inst", "package-sticker"),
showWarnings = FALSE, recursive = TRUE)

path <- file.path(path_proj(), "inst", "package-sticker", "r_logo.png")

if (!file.exists(path)) {
invisible(
file.copy(system.file(file.path("templates", "r_logo.png"),
package = "rcompendium"), path,
overwrite = FALSE))
}


path <- file.path(path_proj(), "inst", "package-sticker",
"package-sticker.R")

if (!file.exists(path)) {
invisible(
file.copy(system.file(file.path("templates", "package-sticker.R"),
package = "rcompendium"), path,
overwrite = FALSE))
}
}


if (!quiet) {
ui_done(paste0("Adding {ui_value('package-sticker.png')} to ",
"{ui_value('README.Rmd')}"))
Expand Down

0 comments on commit f280e36

Please sign in to comment.