Skip to content

Commit 06dc261

Browse files
authored
Merge pull request #265 from ThinkR-open/grkstyle
style: Using grkstyle
2 parents fb04600 + 203bf3f commit 06dc261

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1948
-1004
lines changed

R/add_flat_template.R

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
#' @rdname add_flat_template
44
#' @export
5-
add_additional <- function(pkg = ".",
6-
dev_dir = "dev",
7-
flat_name = "additional",
8-
overwrite = FALSE,
9-
open = TRUE) {
5+
add_additional <- function(
6+
pkg = ".",
7+
dev_dir = "dev",
8+
flat_name = "additional",
9+
overwrite = FALSE,
10+
open = TRUE
11+
) {
1012
add_flat_template(
1113
template = "additional",
1214
pkg = pkg,
@@ -19,11 +21,13 @@ add_additional <- function(pkg = ".",
1921

2022
#' @rdname add_flat_template
2123
#' @export
22-
add_minimal_flat <- function(pkg = ".",
23-
dev_dir = "dev",
24-
flat_name = "minimal",
25-
overwrite = FALSE,
26-
open = TRUE) {
24+
add_minimal_flat <- function(
25+
pkg = ".",
26+
dev_dir = "dev",
27+
flat_name = "minimal",
28+
overwrite = FALSE,
29+
open = TRUE
30+
) {
2731
add_flat_template(
2832
template = "minimal_flat",
2933
pkg = pkg,
@@ -36,11 +40,13 @@ add_minimal_flat <- function(pkg = ".",
3640

3741
#' @rdname add_flat_template
3842
#' @export
39-
add_minimal_package <- function(pkg = ".",
40-
dev_dir = "dev",
41-
flat_name = "minimal",
42-
overwrite = FALSE,
43-
open = TRUE) {
43+
add_minimal_package <- function(
44+
pkg = ".",
45+
dev_dir = "dev",
46+
flat_name = "minimal",
47+
overwrite = FALSE,
48+
open = TRUE
49+
) {
4450
add_flat_template(
4551
template = "minimal_package",
4652
pkg = pkg,
@@ -53,11 +59,13 @@ add_minimal_package <- function(pkg = ".",
5359

5460
#' @rdname add_flat_template
5561
#' @export
56-
add_full <- function(pkg = ".",
57-
dev_dir = "dev",
58-
flat_name = "full",
59-
overwrite = FALSE,
60-
open = TRUE) {
62+
add_full <- function(
63+
pkg = ".",
64+
dev_dir = "dev",
65+
flat_name = "full",
66+
overwrite = FALSE,
67+
open = TRUE
68+
) {
6169
add_flat_template(
6270
template = "full",
6371
pkg = pkg,
@@ -70,10 +78,12 @@ add_full <- function(pkg = ".",
7078

7179
#' @rdname add_flat_template
7280
#' @export
73-
add_dev_history <- function(pkg = ".",
74-
dev_dir = "dev",
75-
overwrite = FALSE,
76-
open = TRUE) {
81+
add_dev_history <- function(
82+
pkg = ".",
83+
dev_dir = "dev",
84+
overwrite = FALSE,
85+
open = TRUE
86+
) {
7787
add_flat_template(
7888
template = "dev_history",
7989
pkg = pkg,
@@ -86,10 +96,16 @@ add_dev_history <- function(pkg = ".",
8696

8797
flat_template_choices <- c(
8898
"full",
89-
"minimal_package", "minpkg",
90-
"minimal_flat", "minflat", "add", "additional",
91-
"teach", "teaching",
92-
"dev_history", "dev"
99+
"minimal_package",
100+
"minpkg",
101+
"minimal_flat",
102+
"minflat",
103+
"add",
104+
"additional",
105+
"teach",
106+
"teaching",
107+
"dev_history",
108+
"dev"
93109
)
94110

95111
create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")
@@ -156,17 +172,20 @@ create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")
156172
#' # add new flat template for teaching (a reduced full template)
157173
#' add_flat_template("teaching")
158174
#' }
159-
add_flat_template <- function(template = c("full", "minimal_package", "minimal_flat", "additional", "teaching", "dev_history"),
160-
pkg = ".",
161-
dev_dir = "dev",
162-
flat_name = NULL,
163-
overwrite = FALSE,
164-
open = TRUE) {
175+
add_flat_template <- function(
176+
template = c("full", "minimal_package", "minimal_flat", "additional", "teaching", "dev_history"),
177+
pkg = ".",
178+
dev_dir = "dev",
179+
flat_name = NULL,
180+
overwrite = FALSE,
181+
open = TRUE
182+
) {
165183
project_name <- get_pkg_name(pkg = pkg)
166184

167185
if (project_name != asciify_name(project_name, to_pkg = TRUE)) {
168186
stop(
169-
"Please rename your project/directory with: `", asciify_name(project_name, to_pkg = TRUE),
187+
"Please rename your project/directory with: `",
188+
asciify_name(project_name, to_pkg = TRUE),
170189
"` as a package name should only contain letters, numbers and dots."
171190
)
172191
}
@@ -207,7 +226,8 @@ add_flat_template <- function(template = c("full", "minimal_package", "minimal_f
207226
}
208227
flat_name <- paste0(
209228
"flat_",
210-
asciify_name(gsub("[.]Rmd$", "", flat_name[1])), ".Rmd"
229+
asciify_name(gsub("[.]Rmd$", "", flat_name[1])),
230+
".Rmd"
211231
)
212232

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

240262
lines_template[grepl("<my_package_name>", lines_template)] <-
241263
gsub(
242-
"<my_package_name>", project_name,
264+
"<my_package_name>",
265+
project_name,
243266
lines_template[grepl("<my_package_name>", lines_template)]
244267
)
245268

246269
# Change flat_template file name
247270
# _inflate
248271
lines_template[grepl("dev/flat_template.Rmd", lines_template)] <-
249272
gsub(
250-
"dev/flat_template.Rmd", file.path(dev_dir, dev_name),
273+
"dev/flat_template.Rmd",
274+
file.path(dev_dir, dev_name),
251275
lines_template[grepl("dev/flat_template.Rmd", lines_template)]
252276
)
253277
# _title
254278
lines_template[grepl("flat_template.Rmd", lines_template)] <-
255279
gsub(
256-
"flat_template.Rmd", dev_name,
280+
"flat_template.Rmd",
281+
dev_name,
257282
lines_template[grepl("flat_template.Rmd", lines_template)]
258283
)
259284

260285
# Change my_fun to fun_name
261286
if (!is.na(fun_name)) {
262287
lines_template[grepl("my_fun", lines_template)] <-
263288
gsub(
264-
"my_fun", fun_name,
289+
"my_fun",
290+
fun_name,
265291
lines_template[grepl("my_fun", lines_template)]
266292
)
267293
}

R/build_fusen_chunks.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#' \dontrun{
1919
#' add_fusen_chunks("this", export = TRUE)
2020
#' }
21-
add_fusen_chunks <- function(function_name = NULL,
22-
export = getOption("fusen.export.functions")) {
21+
add_fusen_chunks <- function(
22+
function_name = NULL,
23+
export = getOption("fusen.export.functions")
24+
) {
2325
if (
2426
requireNamespace("rstudioapi") &&
2527
rstudioapi::isAvailable() &&
@@ -94,7 +96,10 @@ build_fusen_chunks <- function(function_name, export = TRUE) {
9496

9597
if (function_name != cleaned_function_name) {
9698
message(
97-
"Your function name was cleaned: `", function_name, "` is now `", cleaned_function_name,
99+
"Your function name was cleaned: `",
100+
function_name,
101+
"` is now `",
102+
cleaned_function_name,
98103
"` as a function name should only contain letters, numbers and underscores."
99104
)
100105
function_name <- cleaned_function_name

R/create_fusen_rsproject.R

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,32 @@
2020
#' @examples
2121
#' my_path <- tempfile("mypkg")
2222
#' create_fusen(path = my_path, template = "full", open = FALSE)
23-
create_fusen <- function(path,
24-
template = c("full", "minimal", "teaching", "dev_history"),
25-
flat_name = template,
26-
open = TRUE,
27-
overwrite = FALSE,
28-
with_git = FALSE) {
23+
create_fusen <- function(
24+
path,
25+
template = c("full", "minimal", "teaching", "dev_history"),
26+
flat_name = template,
27+
open = TRUE,
28+
overwrite = FALSE,
29+
with_git = FALSE
30+
) {
2931
path <- normalizePath(path, mustWork = FALSE)
3032
template <- match.arg(template, choices = create_fusen_choices)
3133

3234
project_name <- get_pkg_name(pkg = path)
3335
if (project_name != asciify_name(project_name, to_pkg = TRUE)) {
3436
stop(
35-
"Please rename your project/directory with: `", asciify_name(project_name, to_pkg = TRUE),
37+
"Please rename your project/directory with: `",
38+
asciify_name(project_name, to_pkg = TRUE),
3639
"` as a package name should only contain letters, numbers and dots."
3740
)
3841
}
3942

4043
if (dir.exists(path)) {
4144
cli::cli_alert_warning(
4245
paste(
43-
"The path:", path, "already exists."
46+
"The path:",
47+
path,
48+
"already exists."
4449
)
4550
)
4651
if (!isTRUE(overwrite)) {
@@ -120,10 +125,12 @@ create_fusen <- function(path,
120125

121126
#' This will only work with Rstudio Project Wizard
122127
#' @noRd
123-
create_fusen_gui <- function(path,
124-
template,
125-
flat_name = template,
126-
with_git) {
128+
create_fusen_gui <- function(
129+
path,
130+
template,
131+
flat_name = template,
132+
with_git
133+
) {
127134
create_fusen(
128135
path = file.path(normalize_path_winslash(getwd()), path),
129136
template = template,

R/deprecate_flat_file.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#' dev_file <- suppressMessages(
2121
#' add_flat_template(
2222
#' template = "add",
23-
#' pkg = dummypackage, overwrite = TRUE, open = FALSE
23+
#' pkg = dummypackage,
24+
#' overwrite = TRUE,
25+
#' open = FALSE
2426
#' )
2527
#' )
2628
#' deprecate_flat_file(flat_file = "dev/flat_additional.Rmd")
@@ -33,22 +35,25 @@ deprecate_flat_file <- function(flat_file) {
3335
if (!file.exists(flat_file)) {
3436
stop(
3537
paste0(
36-
"The flat file ", basename(flat_file),
38+
"The flat file ",
39+
basename(flat_file),
3740
" does not exist."
3841
)
3942
)
4043
} else if (!basename(flat_file) %in% names(config)) {
4144
stop(
4245
paste0(
43-
"The flat file ", basename(flat_file),
46+
"The flat file ",
47+
basename(flat_file),
4448
" is not in the config file.",
4549
"Did you inflate it with {fusen}?"
4650
)
4751
)
4852
} else if (config[[basename(flat_file)]]$state == "deprecated") {
4953
cli_alert_warning(
5054
paste0(
51-
"The flat file ", basename(flat_file),
55+
"The flat file ",
56+
basename(flat_file),
5257
" is already deprecated."
5358
)
5459
)
@@ -126,7 +131,8 @@ deprecate_flat_file <- function(flat_file) {
126131

127132
cli_alert_success(
128133
paste0(
129-
"The flat file ", basename(flat_file),
134+
"The flat file ",
135+
basename(flat_file),
130136
" has been deprecated."
131137
)
132138
)

R/fill_description.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
#' "Everything can be set from a Rmarkdown file in your project."
2727
#' ),
2828
#' `Authors@R` = c(
29-
#' person("John", "Doe",
29+
#' person(
30+
#' "John",
31+
#' "Doe",
3032
#' email = "[email protected]",
31-
#' role = c("aut", "cre"), comment = c(ORCID = "0000-0000-0000-0000")
33+
#' role = c("aut", "cre"),
34+
#' comment = c(ORCID = "0000-0000-0000-0000")
3235
#' )
3336
#' )
3437
#' )
@@ -46,7 +49,8 @@ fill_description <- function(pkg = ".", fields, overwrite = FALSE) {
4649
clean_pkg_name <- asciify_name(project_name, to_pkg = TRUE)
4750
if (project_name != clean_pkg_name) {
4851
warning(
49-
"Your package was renamed: `", clean_pkg_name,
52+
"Your package was renamed: `",
53+
clean_pkg_name,
5054
"` as a package name should only contain letters, numbers and dots."
5155
)
5256
}

R/get_all_created_funs.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ get_all_created_funs <- function(file) {
2626
parts <- lapply(attr(parts_parsed, "srcref"), as.character)
2727

2828
all_functions <- lapply(
29-
seq_along(parts), function(x) {
29+
seq_along(parts),
30+
function(x) {
3031
out <- list()
3132
out$code <- as.character(parts[x])
3233
name <- parse_fun(out)$fun_name

0 commit comments

Comments
 (0)