Skip to content

Commit acfb42a

Browse files
Merge pull request #1060 from r-lib/single_pkg_namespace
Document imports in a single file
2 parents 7b248d0 + b66dc80 commit acfb42a

Some content is hidden

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

43 files changed

+120
-137
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Roxygen: list(markdown = TRUE, roclets = c( "rd", "namespace", "collate",
5353
if (rlang::is_installed("pkgapi")) "pkgapi::api_roclet" else {
5454
warning("Please install r-lib/pkgapi to make sure the file API is kept
5555
up to date"); NULL}))
56-
RoxygenNote: 7.2.1
56+
RoxygenNote: 7.2.2
5757
Config/testthat/edition: 3
5858
Config/testthat/parallel: true
5959
Collate:
@@ -85,7 +85,7 @@ Collate:
8585
'serialize.R'
8686
'set-assert-args.R'
8787
'style-guides.R'
88-
'styler.R'
88+
'styler-package.R'
8989
'stylerignore.R'
9090
'testing-mocks.R'
9191
'testing-public-api.R'

NAMESPACE

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export(tidyverse_math_token_spacing)
3232
export(tidyverse_reindention)
3333
export(tidyverse_style)
3434
importFrom(magrittr,"%>%")
35-
importFrom(magrittr,or)
36-
importFrom(magrittr,set_names)
37-
importFrom(purrr,as_mapper)
3835
importFrom(purrr,compact)
3936
importFrom(purrr,flatten)
4037
importFrom(purrr,flatten_chr)
@@ -52,11 +49,7 @@ importFrom(purrr,pwalk)
5249
importFrom(purrr,when)
5350
importFrom(rlang,"%||%")
5451
importFrom(rlang,abort)
55-
importFrom(rlang,is_empty)
5652
importFrom(rlang,is_installed)
5753
importFrom(rlang,seq2)
54+
importFrom(rlang,set_names)
5855
importFrom(rlang,warn)
59-
importFrom(rlang,with_handlers)
60-
importFrom(utils,capture.output)
61-
importFrom(utils,tail)
62-
importFrom(utils,write.table)

R/addins.R

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
NULL
4646

4747

48-
#' @importFrom rlang abort
48+
4949
#' @keywords internal
5050
style_active_file <- function() {
5151
communicate_addins_style_transformers()
@@ -118,7 +118,6 @@ save_after_styling_is_active <- function() {
118118
}
119119

120120
#' Styles the highlighted selection in a `.R` or `.Rmd` file.
121-
#' @importFrom rlang abort
122121
#' @keywords internal
123122
style_selection <- function() {
124123
communicate_addins_style_transformers()
@@ -148,9 +147,7 @@ get_rstudio_context <- function() {
148147
}
149148

150149
#' Asks the user to supply a style
151-
#' @importFrom rlang abort
152150
#' @keywords internal
153-
#' @importFrom rlang with_handlers abort
154151
set_style_transformers <- function() {
155152
current_style <- get_addins_style_transformer_name()
156153
new_style <-
@@ -160,7 +157,7 @@ set_style_transformers <- function() {
160157
current_style
161158
)
162159
if (!is.null(new_style)) {
163-
parsed_new_style <- with_handlers(
160+
parsed_new_style <- rlang::with_handlers(
164161
{
165162
transformers <- eval(parse(text = new_style))
166163
style_text(
@@ -182,7 +179,6 @@ set_style_transformers <- function() {
182179
}
183180

184181
#' Return the style function or name
185-
#'
186182
#' @keywords internal
187183
get_addins_style_transformer_name <- function() {
188184
getOption("styler.addins_style_transformer")
@@ -210,10 +206,9 @@ communicate_addins_style_transformers <- function() {
210206
#' @param context The context from `styler:::get_rstudio_context()`.
211207
#' @param transformer A transformer function most conveniently constructed with
212208
#' [make_transformer()].
213-
#' @importFrom rlang with_handlers abort
214209
#' @keywords internal
215210
try_transform_as_r_file <- function(context, transformer) {
216-
with_handlers(
211+
rlang::with_handlers(
217212
transformer(context$contents),
218213
error = function(e) {
219214
preamble_for_unsaved <- paste(

R/communicate.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ communicate_summary <- function(changed, ruler_width) {
4040
}
4141
}
4242

43-
#' @importFrom rlang abort
44-
#' @importFrom rlang is_installed
43+
4544
assert_data.tree_installation <- function() {
4645
if (!is_installed("data.tree")) {
4746
abort("The package data.tree needs to be installed for this functionality.")

R/compat-dplyr.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lead <- function(x, n = 1L, default = NA) {
1010
c(x[-seq_len(n)], rep(default, n))
1111
}
1212

13-
#' @importFrom rlang abort
13+
1414
arrange <- function(.data, ...) {
1515
ord <- eval(substitute(order(...)), .data, parent.frame())
1616
.data[ord, , drop = FALSE]
@@ -81,9 +81,8 @@ slice <- function(.data, ...) {
8181
}
8282

8383
# TODO: Use `purrr::map_dfr()` when it stops implicitly relying on `{dplyr}`
84-
#' @importFrom purrr as_mapper map
8584
map_dfr <- function(.x, .f, ..., .id = NULL) {
86-
.f <- as_mapper(.f, ...)
85+
.f <- purrr::as_mapper(.f, ...)
8786
res <- map(.x, .f, ...)
8887
bind_rows(res, .id = .id)
8988
}

R/detect-alignment-utils.R

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#' Must be after dropping comments because the closing brace is only guaranteed
44
#' to be the last token in that case.
55
#' @inheritParams alignment_drop_comments
6-
#' @importFrom rlang seq2
76
#' @keywords internal
87
alignment_ensure_no_closing_brace <- function(pd_by_line,
98
last_line_droped_early) {
@@ -28,7 +27,6 @@ alignment_ensure_no_closing_brace <- function(pd_by_line,
2827
#' @param pd_by_line A list, each element corresponding to a potentially
2928
#' incomplete parse table that represents all token from one line.
3029
#' @keywords internal
31-
#' @importFrom purrr map compact
3230
alignment_drop_comments <- function(pd_by_line) {
3331
map(pd_by_line, function(x) {
3432
out <- x[x$token != "COMMENT", ]
@@ -107,7 +105,6 @@ alignment_ensure_trailing_comma <- function(pd_by_line) {
107105
#' Checks if all arguments of column 1 are named
108106
#' @param relevant_pd_by_line A list with parse tables of a multi-line call,
109107
#' excluding first and last column.
110-
#' @importFrom purrr map_lgl
111108
#' @keywords internal
112109
alignment_col1_all_named <- function(relevant_pd_by_line) {
113110
map_lgl(relevant_pd_by_line, function(x) {
@@ -124,15 +121,13 @@ alignment_col1_all_named <- function(relevant_pd_by_line) {
124121
#' Serialize all lines for a given column
125122
#' @param column The index of the column to serialize.
126123
#' @inheritParams alignment_col1_all_named
127-
#' @importFrom purrr map
128124
#' @keywords internal
129125
alignment_serialize_column <- function(relevant_pd_by_line, column) {
130126
map(relevant_pd_by_line, alignment_serialize_line, column = column)
131127
}
132128

133129
#' Serialize one line for a column
134130
#'
135-
#'
136131
#' @inheritParams alignment_serialize_column
137132
#' @inheritParams alignment_col1_all_named
138133
#' @keywords internal
@@ -147,7 +142,7 @@ alignment_serialize_line <- function(relevant_pd_by_line, column) {
147142
# line does not have values at that column
148143
return(NULL)
149144
}
150-
between_commas <- seq2(max(1, comma_idx[column - 1L]), comma_idx[column])
145+
between_commas <- seq2(max(1L, comma_idx[column - 1L]), comma_idx[column])
151146
relevant_pd_by_line <- relevant_pd_by_line[between_commas, ]
152147
alignment_serialize(relevant_pd_by_line)
153148
}
@@ -178,7 +173,7 @@ alignment_serialize <- function(pd_sub) {
178173
#' At least one space after comma, none before, for all but the last comma on
179174
#' the line
180175
#' @param pd_sub The subset of a parse table corresponding to one line.
181-
#' @importFrom rlang seq2
176+
#'
182177
#' @keywords internal
183178
alignment_has_correct_spacing_around_comma <- function(pd_sub) {
184179
comma_tokens <- which(pd_sub$token == "','")
@@ -196,14 +191,13 @@ alignment_has_correct_spacing_around_comma <- function(pd_sub) {
196191
#' At least one space around `EQ_SUB`
197192
#' @inheritParams alignment_has_correct_spacing_around_comma
198193
#' @keywords internal
199-
#' @importFrom rlang seq2
200194
alignment_has_correct_spacing_around_eq_sub <- function(pd_sub) {
201195
relevant_eq_sub_token <- which(pd_sub$token == "EQ_SUB")
202196
if (length(relevant_eq_sub_token) == 0L) {
203197
return(TRUE)
204198
}
205199

206-
correct_spaces_before <- pd_sub$.lag_spaces[relevant_eq_sub_token] >= 1
207-
correct_spaces_after <- pd_sub$spaces[relevant_eq_sub_token] >= 1
200+
correct_spaces_before <- pd_sub$.lag_spaces[relevant_eq_sub_token] >= 1L
201+
correct_spaces_after <- pd_sub$spaces[relevant_eq_sub_token] >= 1L
208202
all(correct_spaces_before) && all(correct_spaces_after)
209203
}

R/detect-alignment.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#' * For the recursive creation of text, greedily check column by column to make
2323
#' sure we can stop as soon as we found that columns are not aligned.
2424
#'
25-
#' @importFrom purrr map_int map_lgl map compact
26-
#' @importFrom rlang seq2
2725
#' @keywords internal
2826
#' @examples
2927
#' library("magrittr")

R/indent.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ indent_without_paren_for_while_fun <- function(pd, indent_by) {
2929
}
3030

3131
#' @describeIn update_indention Is used to indent if and if-else statements.
32-
#' @importFrom rlang seq2
32+
#'
3333
#' @keywords internal
3434
indent_without_paren_if_else <- function(pd, indent_by) {
3535
expr_after_if <- next_non_comment(pd, which(pd$token == "')'")[1L])
@@ -91,7 +91,7 @@ indent_without_paren_if_else <- function(pd, indent_by) {
9191
#' Since text `[[` has token `"LBB"` and text `]]` is parsed as two independent
9292
#' `]` (see 'Examples'), indention has to stop at the first `]`.
9393
# one token earlier
94-
#' @importFrom rlang seq2
94+
#'
9595
#' @keywords internal
9696
#' @examples
9797
#' styler:::parse_text("a[1]")
@@ -161,7 +161,7 @@ needs_indention <- function(pd,
161161
#' if on the same line as the token corresponding to `potential_trigger` and
162162
#' directly followed by a line break.
163163
#' @return `TRUE` if indention is needed, `FALSE` otherwise.
164-
#' @importFrom rlang seq2
164+
#'
165165
#' @keywords internal
166166
#' @examples
167167
#' style_text(c(
@@ -206,7 +206,6 @@ needs_indention_one <- function(pd,
206206
#' Sets the column `multi_line` in `pd` by checking row-wise whether any child
207207
#' of a token is a multi-line token.
208208
#' @param pd A parse table.
209-
#' @importFrom purrr map_lgl
210209
#' @keywords internal
211210
set_multi_line <- function(pd) {
212211
pd$multi_line <- unname(map_int(pd$child, pd_multi_line))

R/initialize.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#' This function initializes and removes various variables from the parse
44
#' table.
55
#' @param pd_flat A parse table.
6-
#' @importFrom utils tail
76
#' @examples
87
#' withr::with_options(
98
#' list(styler.cache_name = NULL), # temporarily deactivate cache
@@ -37,7 +36,7 @@ NULL
3736
#' @describeIn initialize_attributes Initializes `newlines` and `lag_newlines`.
3837
#' @keywords internal
3938
initialize_newlines <- function(pd_flat) {
40-
pd_flat$line3 <- lead(pd_flat$line1, default = tail(pd_flat$line2, 1L))
39+
pd_flat$line3 <- lead(pd_flat$line1, default = utils::tail(pd_flat$line2, 1L))
4140
pd_flat$newlines <- pd_flat$line3 - pd_flat$line2
4241
pd_flat$lag_newlines <- lag(pd_flat$newlines, default = 0L)
4342
pd_flat$line3 <- NULL
@@ -47,7 +46,7 @@ initialize_newlines <- function(pd_flat) {
4746
#' @describeIn initialize_attributes Initializes `spaces`.
4847
#' @keywords internal
4948
initialize_spaces <- function(pd_flat) {
50-
pd_flat$col3 <- lead(pd_flat$col1, default = tail(pd_flat$col2, 1L) + 1L)
49+
pd_flat$col3 <- lead(pd_flat$col1, default = utils::tail(pd_flat$col2, 1L) + 1L)
5150
pd_flat$col2_nl <- ifelse(pd_flat$newlines > 0L,
5251
rep(0L, nrow(pd_flat)), pd_flat$col2
5352
)
@@ -88,7 +87,7 @@ initialize_indent <- function(pd_flat) {
8887
pd_flat
8988
}
9089

91-
#' @importFrom rlang abort
90+
9291
#' @describeIn initialize_attributes validates the parse data.
9392
#' @keywords internal
9493
validate_parse_data <- function(pd_flat) {

R/io.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#' Apply a function to the contents of a file
22
#'
33
#' Transforms a file with a function.
4-
#' @importFrom magrittr set_names
5-
#' @importFrom rlang abort
64
#' @inheritParams transform_utf8_one
75
#' @keywords internal
86
transform_utf8 <- function(path, fun, dry) {
@@ -19,11 +17,10 @@ transform_utf8 <- function(path, fun, dry) {
1917
#' latter returns an error if the input code is not identical to the result
2018
#' of styling. "off", the default, writes back if the input and output of
2119
#' styling are not identical.
22-
#' @importFrom rlang with_handlers warn
2320
#' @keywords internal
2421
transform_utf8_one <- function(path, fun, dry) {
2522
rlang::arg_match(dry, c("on", "off", "fail"))
26-
with_handlers(
23+
rlang::with_handlers(
2724
{
2825
file_with_info <- read_utf8(path)
2926
# only write back when changed OR when there was a missing newline

0 commit comments

Comments
 (0)