Skip to content

Commit

Permalink
style: Using grkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
yohann committed Jun 17, 2024
1 parent fb04600 commit 203bf3f
Show file tree
Hide file tree
Showing 54 changed files with 1,948 additions and 1,004 deletions.
110 changes: 68 additions & 42 deletions R/add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#' @rdname add_flat_template
#' @export
add_additional <- function(pkg = ".",
dev_dir = "dev",
flat_name = "additional",
overwrite = FALSE,
open = TRUE) {
add_additional <- function(
pkg = ".",
dev_dir = "dev",
flat_name = "additional",
overwrite = FALSE,
open = TRUE
) {
add_flat_template(
template = "additional",
pkg = pkg,
Expand All @@ -19,11 +21,13 @@ add_additional <- function(pkg = ".",

#' @rdname add_flat_template
#' @export
add_minimal_flat <- function(pkg = ".",
dev_dir = "dev",
flat_name = "minimal",
overwrite = FALSE,
open = TRUE) {
add_minimal_flat <- function(
pkg = ".",
dev_dir = "dev",
flat_name = "minimal",
overwrite = FALSE,
open = TRUE
) {
add_flat_template(
template = "minimal_flat",
pkg = pkg,
Expand All @@ -36,11 +40,13 @@ add_minimal_flat <- function(pkg = ".",

#' @rdname add_flat_template
#' @export
add_minimal_package <- function(pkg = ".",
dev_dir = "dev",
flat_name = "minimal",
overwrite = FALSE,
open = TRUE) {
add_minimal_package <- function(
pkg = ".",
dev_dir = "dev",
flat_name = "minimal",
overwrite = FALSE,
open = TRUE
) {
add_flat_template(
template = "minimal_package",
pkg = pkg,
Expand All @@ -53,11 +59,13 @@ add_minimal_package <- function(pkg = ".",

#' @rdname add_flat_template
#' @export
add_full <- function(pkg = ".",
dev_dir = "dev",
flat_name = "full",
overwrite = FALSE,
open = TRUE) {
add_full <- function(
pkg = ".",
dev_dir = "dev",
flat_name = "full",
overwrite = FALSE,
open = TRUE
) {
add_flat_template(
template = "full",
pkg = pkg,
Expand All @@ -70,10 +78,12 @@ add_full <- function(pkg = ".",

#' @rdname add_flat_template
#' @export
add_dev_history <- function(pkg = ".",
dev_dir = "dev",
overwrite = FALSE,
open = TRUE) {
add_dev_history <- function(
pkg = ".",
dev_dir = "dev",
overwrite = FALSE,
open = TRUE
) {
add_flat_template(
template = "dev_history",
pkg = pkg,
Expand All @@ -86,10 +96,16 @@ add_dev_history <- function(pkg = ".",

flat_template_choices <- c(
"full",
"minimal_package", "minpkg",
"minimal_flat", "minflat", "add", "additional",
"teach", "teaching",
"dev_history", "dev"
"minimal_package",
"minpkg",
"minimal_flat",
"minflat",
"add",
"additional",
"teach",
"teaching",
"dev_history",
"dev"
)

create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")
Expand Down Expand Up @@ -156,17 +172,20 @@ create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")
#' # add new flat template for teaching (a reduced full template)
#' add_flat_template("teaching")
#' }
add_flat_template <- function(template = c("full", "minimal_package", "minimal_flat", "additional", "teaching", "dev_history"),
pkg = ".",
dev_dir = "dev",
flat_name = NULL,
overwrite = FALSE,
open = TRUE) {
add_flat_template <- function(
template = c("full", "minimal_package", "minimal_flat", "additional", "teaching", "dev_history"),
pkg = ".",
dev_dir = "dev",
flat_name = NULL,
overwrite = FALSE,
open = TRUE
) {
project_name <- get_pkg_name(pkg = pkg)

if (project_name != asciify_name(project_name, to_pkg = TRUE)) {
stop(
"Please rename your project/directory with: `", asciify_name(project_name, to_pkg = TRUE),
"Please rename your project/directory with: `",
asciify_name(project_name, to_pkg = TRUE),
"` as a package name should only contain letters, numbers and dots."
)
}
Expand Down Expand Up @@ -207,7 +226,8 @@ add_flat_template <- function(template = c("full", "minimal_package", "minimal_f
}
flat_name <- paste0(
"flat_",
asciify_name(gsub("[.]Rmd$", "", flat_name[1])), ".Rmd"
asciify_name(gsub("[.]Rmd$", "", flat_name[1])),
".Rmd"
)

pkg <- normalizePath(pkg)
Expand All @@ -227,8 +247,10 @@ add_flat_template <- function(template = c("full", "minimal_package", "minimal_f
n <- length(list.files(full_dev_dir, pattern = "^flat_.*[.]Rmd"))
dev_file_path <- file.path(full_dev_dir, paste0(file_path_sans_ext(flat_name), "_", n + 1, ".Rmd"))
message(
flat_name, " already exists. New flat file is renamed '",
basename(dev_file_path), "'. Use overwrite = TRUE, if you want to ",
flat_name,
" already exists. New flat file is renamed '",
basename(dev_file_path),
"'. Use overwrite = TRUE, if you want to ",
"overwrite the existing file or rename it."
)
}
Expand All @@ -239,29 +261,33 @@ add_flat_template <- function(template = c("full", "minimal_package", "minimal_f

lines_template[grepl("<my_package_name>", lines_template)] <-
gsub(
"<my_package_name>", project_name,
"<my_package_name>",
project_name,
lines_template[grepl("<my_package_name>", lines_template)]
)

# Change flat_template file name
# _inflate
lines_template[grepl("dev/flat_template.Rmd", lines_template)] <-
gsub(
"dev/flat_template.Rmd", file.path(dev_dir, dev_name),
"dev/flat_template.Rmd",
file.path(dev_dir, dev_name),
lines_template[grepl("dev/flat_template.Rmd", lines_template)]
)
# _title
lines_template[grepl("flat_template.Rmd", lines_template)] <-
gsub(
"flat_template.Rmd", dev_name,
"flat_template.Rmd",
dev_name,
lines_template[grepl("flat_template.Rmd", lines_template)]
)

# Change my_fun to fun_name
if (!is.na(fun_name)) {
lines_template[grepl("my_fun", lines_template)] <-
gsub(
"my_fun", fun_name,
"my_fun",
fun_name,
lines_template[grepl("my_fun", lines_template)]
)
}
Expand Down
11 changes: 8 additions & 3 deletions R/build_fusen_chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#' \dontrun{
#' add_fusen_chunks("this", export = TRUE)
#' }
add_fusen_chunks <- function(function_name = NULL,
export = getOption("fusen.export.functions")) {
add_fusen_chunks <- function(
function_name = NULL,
export = getOption("fusen.export.functions")
) {
if (
requireNamespace("rstudioapi") &&
rstudioapi::isAvailable() &&
Expand Down Expand Up @@ -94,7 +96,10 @@ build_fusen_chunks <- function(function_name, export = TRUE) {

if (function_name != cleaned_function_name) {
message(
"Your function name was cleaned: `", function_name, "` is now `", cleaned_function_name,
"Your function name was cleaned: `",
function_name,
"` is now `",
cleaned_function_name,
"` as a function name should only contain letters, numbers and underscores."
)
function_name <- cleaned_function_name
Expand Down
31 changes: 19 additions & 12 deletions R/create_fusen_rsproject.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,32 @@
#' @examples
#' my_path <- tempfile("mypkg")
#' create_fusen(path = my_path, template = "full", open = FALSE)
create_fusen <- function(path,
template = c("full", "minimal", "teaching", "dev_history"),
flat_name = template,
open = TRUE,
overwrite = FALSE,
with_git = FALSE) {
create_fusen <- function(
path,
template = c("full", "minimal", "teaching", "dev_history"),
flat_name = template,
open = TRUE,
overwrite = FALSE,
with_git = FALSE
) {
path <- normalizePath(path, mustWork = FALSE)
template <- match.arg(template, choices = create_fusen_choices)

project_name <- get_pkg_name(pkg = path)
if (project_name != asciify_name(project_name, to_pkg = TRUE)) {
stop(
"Please rename your project/directory with: `", asciify_name(project_name, to_pkg = TRUE),
"Please rename your project/directory with: `",
asciify_name(project_name, to_pkg = TRUE),
"` as a package name should only contain letters, numbers and dots."
)
}

if (dir.exists(path)) {
cli::cli_alert_warning(
paste(
"The path:", path, "already exists."
"The path:",
path,
"already exists."
)
)
if (!isTRUE(overwrite)) {
Expand Down Expand Up @@ -120,10 +125,12 @@ create_fusen <- function(path,

#' This will only work with Rstudio Project Wizard
#' @noRd
create_fusen_gui <- function(path,
template,
flat_name = template,
with_git) {
create_fusen_gui <- function(
path,
template,
flat_name = template,
with_git
) {
create_fusen(
path = file.path(normalize_path_winslash(getwd()), path),
template = template,
Expand Down
16 changes: 11 additions & 5 deletions R/deprecate_flat_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#' dev_file <- suppressMessages(
#' add_flat_template(
#' template = "add",
#' pkg = dummypackage, overwrite = TRUE, open = FALSE
#' pkg = dummypackage,
#' overwrite = TRUE,
#' open = FALSE
#' )
#' )
#' deprecate_flat_file(flat_file = "dev/flat_additional.Rmd")
Expand All @@ -33,22 +35,25 @@ deprecate_flat_file <- function(flat_file) {
if (!file.exists(flat_file)) {
stop(
paste0(
"The flat file ", basename(flat_file),
"The flat file ",
basename(flat_file),
" does not exist."
)
)
} else if (!basename(flat_file) %in% names(config)) {
stop(
paste0(
"The flat file ", basename(flat_file),
"The flat file ",
basename(flat_file),
" is not in the config file.",
"Did you inflate it with {fusen}?"
)
)
} else if (config[[basename(flat_file)]]$state == "deprecated") {
cli_alert_warning(
paste0(
"The flat file ", basename(flat_file),
"The flat file ",
basename(flat_file),
" is already deprecated."
)
)
Expand Down Expand Up @@ -126,7 +131,8 @@ deprecate_flat_file <- function(flat_file) {

cli_alert_success(
paste0(
"The flat file ", basename(flat_file),
"The flat file ",
basename(flat_file),
" has been deprecated."
)
)
Expand Down
10 changes: 7 additions & 3 deletions R/fill_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
#' "Everything can be set from a Rmarkdown file in your project."
#' ),
#' `Authors@R` = c(
#' person("John", "Doe",
#' person(
#' "John",
#' "Doe",
#' email = "[email protected]",
#' role = c("aut", "cre"), comment = c(ORCID = "0000-0000-0000-0000")
#' role = c("aut", "cre"),
#' comment = c(ORCID = "0000-0000-0000-0000")
#' )
#' )
#' )
Expand All @@ -46,7 +49,8 @@ fill_description <- function(pkg = ".", fields, overwrite = FALSE) {
clean_pkg_name <- asciify_name(project_name, to_pkg = TRUE)
if (project_name != clean_pkg_name) {
warning(
"Your package was renamed: `", clean_pkg_name,
"Your package was renamed: `",
clean_pkg_name,
"` as a package name should only contain letters, numbers and dots."
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/get_all_created_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ get_all_created_funs <- function(file) {
parts <- lapply(attr(parts_parsed, "srcref"), as.character)

all_functions <- lapply(
seq_along(parts), function(x) {
seq_along(parts),
function(x) {
out <- list()
out$code <- as.character(parts[x])
name <- parse_fun(out)$fun_name
Expand Down
Loading

0 comments on commit 203bf3f

Please sign in to comment.