19
19
# ' conveniently constructed via the `style` argument and `...`. See
20
20
# ' 'Examples'.
21
21
# ' @param filetype Vector of file extensions indicating which filetypes should
22
- # ' be styled. Case is ignored, and the `.` is optional, e.g. c(".R", ".Rmd")
23
- # ' or c("r", "rmd").
22
+ # ' be styled. Case is ignored, and the `.` is optional, e.g. ` c(".R", ".Rmd")`
23
+ # ' or ` c("r", "rmd")` .
24
24
# ' @param exclude_files Character vector with paths to files that should be
25
25
# ' excluded from styling.
26
26
# ' @section Warning:
@@ -44,44 +44,32 @@ style_pkg <- function(pkg = ".",
44
44
exclude_files = " R/RcppExports.R" ) {
45
45
pkg_root <- rprojroot :: find_package_root_file(path = pkg )
46
46
changed <- withr :: with_dir(pkg_root ,
47
- prettify_local (transformers , filetype , exclude_files )
47
+ prettify_pkg (transformers , filetype , exclude_files )
48
48
)
49
49
invisible (changed )
50
50
}
51
51
52
- prettify_local <- function (transformers , filetype , exclude_files ) {
52
+ prettify_pkg <- function (transformers , filetype , exclude_files ) {
53
53
54
54
filetype <- set_and_assert_arg_filetype(filetype )
55
- r_files <- test_files <- data_raw_files <- vignette_files <- readme <- NULL
55
+ r_files <- vignette_files <- readme <- NULL
56
56
57
57
if (" \\ .r" %in% filetype ) {
58
58
r_files <- dir(
59
- path = " R" , pattern = " \\ .r$" , ignore.case = TRUE ,
60
- recursive = TRUE , full.names = TRUE
61
- )
62
- test_files <- dir(
63
- path = " tests" , pattern = " \\ .r$" , ignore.case = TRUE ,
64
- recursive = TRUE , full.names = TRUE
65
- )
66
- data_raw_files <- dir(
67
- path = " data-raw" , pattern = " \\ .r$" , ignore.case = TRUE ,
68
- recursive = TRUE , full.names = TRUE
59
+ path = c(" R" , " tests" , " data-raw" ), pattern = " \\ .r$" ,
60
+ ignore.case = TRUE , recursive = TRUE , full.names = TRUE
69
61
)
70
62
}
71
63
72
64
if (" \\ .rmd" %in% filetype ) {
73
65
vignette_files <- dir(
74
- path = " vignettes" , pattern = " \\ .rmd$" , ignore.case = TRUE ,
75
- recursive = TRUE , full.names = TRUE
66
+ path = " vignettes" , pattern = " \\ .rmd$" ,
67
+ ignore.case = TRUE , recursive = TRUE , full.names = TRUE
76
68
)
77
- readme <- dir(pattern = " readme\\ .rmd" , ignore.case = TRUE )
69
+ readme <- dir(pattern = " ^ readme\\ .rmd$ " , ignore.case = TRUE )
78
70
}
79
71
80
- files <- setdiff(
81
- c(r_files , test_files , data_raw_files , vignette_files , readme ),
82
- exclude_files
83
- )
84
-
72
+ files <- setdiff(c(r_files , vignette_files , readme ), exclude_files )
85
73
transform_files(files , transformers )
86
74
}
87
75
0 commit comments