Skip to content

Commit 55e6066

Browse files
thisisniczanmato1984
authored andcommitted
apacheGH-46592: [CI][Dev][R] Add Air to pre-commit (apache#47423)
### Rationale for this change It's faster than styler ### What changes are included in this PR? Adding it ### Are these changes tested? Yep ### Are there any user-facing changes? Nah * GitHub Issue: apache#46592 Authored-by: Nic Crane <[email protected]> Signed-off-by: Nic Crane <[email protected]>
1 parent e4c03c0 commit 55e6066

File tree

155 files changed

+2713
-1990
lines changed

Some content is hidden

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

155 files changed

+2713
-1990
lines changed

.github/workflows/dev.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ jobs:
6060
- name: Cache pre-commit
6161
uses: actions/cache@v4
6262
with:
63-
path: |
64-
~/.cache/pre-commit
65-
~/.local/share/renv/cache
63+
path: ~/.cache/pre-commit
6664
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
65+
- name: Install Air
66+
uses: posit-dev/setup-air@63e80dedb6d275c94a3841e15e5ff8691e1ab237 # v1.0.0
6767
- name: Run pre-commit
6868
run: |
6969
pre-commit run --all-files --color=always --show-diff-on-failure

.pre-commit-config.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,13 @@ repos:
205205
^r/.*\.(R|Rmd)$
206206
- repo: local
207207
hooks:
208-
- id: styler
208+
- id: air-format
209209
alias: r
210-
name: R Format
211-
language: r
212-
additional_dependencies:
213-
- roxygen2
214-
- styler
215-
entry: |
216-
Rscript -e "styler::style_file(commandArgs(TRUE)[1])"
210+
name: R Format (Air)
211+
language: system
212+
entry: air format r --check
217213
files: >-
218-
^r/.*\.(R|Rmd)$
214+
^r/.*\.R$
219215
- repo: https://github.com/pre-commit/mirrors-clang-format
220216
rev: v14.0.6
221217
hooks:

docs/source/developers/guide/step_by_step/styling.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ linters and styling of the code.
3535

3636
.. tab-item:: R package
3737

38-
For the R package you can use ``{lintr}`` or ``{styler}``
38+
For the R package you can use
39+
`air <https://posit-dev.github.io/air/>`_ to format the code,
40+
and
41+
42+
``{lintr}``
3943
to check if the code follows the
4044
`tidyverse style <https://style.tidyverse.org/>`_.
4145

42-
The instructions on how to use either of these two packages
46+
The instructions on how to use `air` and ``{lintr}``
4347
can be found in the
4448
`Styling and Linting section of the Common developer workflow tasks <https://arrow.apache.org/docs/r/articles/developers/workflow.html#styling-and-linting>`_.
4549

r/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Imports:
4444
utils,
4545
vctrs
4646
Roxygen: list(markdown = TRUE, r6 = FALSE, load = "source")
47-
RoxygenNote: 7.3.1
47+
RoxygenNote: 7.3.3
4848
Config/testthat/edition: 3
4949
Config/build/bootstrap: TRUE
5050
Suggests:

r/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ ARROW_R_DEV="TRUE"
2020
ARROW_LARGE_MEMORY_TESTS=$(ARROW_R_DEV)
2121

2222
style:
23-
pre-commit run --show-diff-on-failure --color=always styler
23+
pre-commit run --show-diff-on-failure --color=always r
2424

2525
style-all:
26-
pre-commit run --show-diff-on-failure --color=always --all-files styler
26+
pre-commit run --show-diff-on-failure --color=always --all-files r
2727

2828
doc: style
2929
R -s -f data-raw/docgen.R

r/R/array-data.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
#' @rdname ArrayData
4242
#' @name ArrayData
4343
#' @include type.R
44-
ArrayData <- R6Class("ArrayData",
44+
ArrayData <- R6Class(
45+
"ArrayData",
4546
inherit = ArrowObject,
4647
active = list(
4748
type = function() ArrayData__get_type(self),

r/R/array.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
#' na_array2 == na_array # element-wise comparison
106106
#' na_array2$Equals(na_array) # overall comparison
107107
#' @export
108-
Array <- R6Class("Array",
108+
Array <- R6Class(
109+
"Array",
109110
inherit = ArrowDatum,
110111
public = list(
111112
IsNull = function(i) Array__IsNull(self, i),
@@ -199,7 +200,8 @@ Array$create <- function(x, type = NULL) {
199200
error = function(cnd) {
200201
attempt <- try(vec_to_Array(x, NULL)$cast(type), silent = TRUE)
201202
abort(
202-
c(conditionMessage(cnd),
203+
c(
204+
conditionMessage(cnd),
203205
i = if (!inherits(attempt, "try-error")) {
204206
"You might want to try casting manually with `Array$create(...)$cast(...)`."
205207
}
@@ -397,7 +399,8 @@ c.Array <- function(...) {
397399
#' @usage NULL
398400
#' @format NULL
399401
#' @export
400-
DictionaryArray <- R6Class("DictionaryArray",
402+
DictionaryArray <- R6Class(
403+
"DictionaryArray",
401404
inherit = Array,
402405
public = list(
403406
indices = function() DictionaryArray__indices(self),
@@ -429,7 +432,8 @@ DictionaryArray$create <- function(x, dict = NULL) {
429432
#' @usage NULL
430433
#' @format NULL
431434
#' @export
432-
StructArray <- R6Class("StructArray",
435+
StructArray <- R6Class(
436+
"StructArray",
433437
inherit = Array,
434438
public = list(
435439
field = function(i) StructArray__field(self, i),
@@ -480,7 +484,8 @@ as.data.frame.StructArray <- function(x, row.names = NULL, optional = FALSE, ...
480484
#' @usage NULL
481485
#' @format NULL
482486
#' @export
483-
ListArray <- R6Class("ListArray",
487+
ListArray <- R6Class(
488+
"ListArray",
484489
inherit = Array,
485490
public = list(
486491
values = function() ListArray__values(self),
@@ -497,7 +502,8 @@ ListArray <- R6Class("ListArray",
497502
#' @usage NULL
498503
#' @format NULL
499504
#' @export
500-
LargeListArray <- R6Class("LargeListArray",
505+
LargeListArray <- R6Class(
506+
"LargeListArray",
501507
inherit = Array,
502508
public = list(
503509
values = function() LargeListArray__values(self),
@@ -514,7 +520,8 @@ LargeListArray <- R6Class("LargeListArray",
514520
#' @usage NULL
515521
#' @format NULL
516522
#' @export
517-
FixedSizeListArray <- R6Class("FixedSizeListArray",
523+
FixedSizeListArray <- R6Class(
524+
"FixedSizeListArray",
518525
inherit = Array,
519526
public = list(
520527
values = function() FixedSizeListArray__values(self),
@@ -527,7 +534,8 @@ FixedSizeListArray <- R6Class("FixedSizeListArray",
527534
)
528535
)
529536

530-
is.Array <- function(x, type = NULL) { # nolint
537+
is.Array <- function(x, type = NULL) {
538+
# nolint
531539
is_it <- inherits(x, c("Array", "ChunkedArray"))
532540
if (is_it && !is.null(type)) {
533541
is_it <- x$type$ToString() %in% type
@@ -539,7 +547,8 @@ is.Array <- function(x, type = NULL) { # nolint
539547
#' @usage NULL
540548
#' @format NULL
541549
#' @export
542-
MapArray <- R6Class("MapArray",
550+
MapArray <- R6Class(
551+
"MapArray",
543552
inherit = ListArray,
544553
public = list(
545554
keys = function() MapArray__keys(self),

r/R/arrow-datum.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
# Base class for Array, ChunkedArray, and Scalar, for S3 method dispatch only.
2121
# Does not exist in C++ class hierarchy
22-
ArrowDatum <- R6Class("ArrowDatum",
22+
ArrowDatum <- R6Class(
23+
"ArrowDatum",
2324
inherit = ArrowObject,
2425
public = list(
2526
cast = function(target_type, safe = TRUE, ...) {
@@ -81,14 +82,16 @@ as.vector.ArrowDatum <- function(x, mode) {
8182
#' @export
8283
Ops.ArrowDatum <- function(e1, e2) {
8384
if (missing(e2)) {
84-
switch(.Generic,
85+
switch(
86+
.Generic,
8587
"!" = return(eval_array_expression(.Generic, e1)),
8688
"+" = return(eval_array_expression(.Generic, 0L, e1)),
8789
"-" = return(eval_array_expression("negate_checked", e1)),
8890
)
8991
}
9092

91-
switch(.Generic,
93+
switch(
94+
.Generic,
9295
"+" = ,
9396
"-" = ,
9497
"*" = ,
@@ -112,7 +115,8 @@ Ops.ArrowDatum <- function(e1, e2) {
112115

113116
#' @export
114117
Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
115-
switch(.Generic,
118+
switch(
119+
.Generic,
116120
abs = eval_array_expression("abs_checked", x),
117121
ceiling = eval_array_expression("ceil", x),
118122
sign = eval_array_expression("sign", x),
@@ -161,10 +165,7 @@ Math.ArrowDatum <- function(x, ..., base = exp(1), digits = 0) {
161165
# Wrapper around call_function that:
162166
# (1) maps R function names to Arrow C++ compute ("/" --> "divide_checked")
163167
# (2) wraps R input args as Array or Scalar
164-
eval_array_expression <- function(FUN,
165-
...,
166-
args = list(...),
167-
options = empty_named_list()) {
168+
eval_array_expression <- function(FUN, ..., args = list(...), options = empty_named_list()) {
168169
if (FUN == "-" && length(args) == 1L) {
169170
if (inherits(args[[1]], "ArrowObject")) {
170171
return(eval_array_expression("negate_checked", args[[1]]))

r/R/arrow-info.R

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,14 @@ print.arrow_info <- function(x, ...) {
157157
cat("\n")
158158
}
159159
cat("Arrow package version: ", format(x$version), "\n\n", sep = "")
160-
print_key_values("Capabilities", c(
161-
x$capabilities,
162-
jemalloc = "jemalloc" %in% x$memory_pool$available_backends,
163-
mimalloc = "mimalloc" %in% x$memory_pool$available_backends
164-
))
160+
print_key_values(
161+
"Capabilities",
162+
c(
163+
x$capabilities,
164+
jemalloc = "jemalloc" %in% x$memory_pool$available_backends,
165+
mimalloc = "mimalloc" %in% x$memory_pool$available_backends
166+
)
167+
)
165168
if (some_features_are_off(x$capabilities) && identical(tolower(Sys.info()[["sysname"]]), "linux")) {
166169
# Only on linux because (e.g.) we disable certain features on purpose on rtools35
167170
cat(
@@ -177,22 +180,31 @@ print.arrow_info <- function(x, ...) {
177180
format_bytes <- function(b, units = "auto", digits = 2L, ...) {
178181
format(structure(b, class = "object_size"), units = units, digits = digits, ...)
179182
}
180-
print_key_values("Memory", c(
181-
Allocator = x$memory_pool$backend_name,
182-
# utils:::format.object_size is not properly vectorized
183-
Current = format_bytes(x$memory_pool$bytes_allocated, ...),
184-
Max = format_bytes(x$memory_pool$max_memory, ...)
185-
))
186-
print_key_values("Runtime", c(
187-
`SIMD Level` = x$runtime_info$simd_level,
188-
`Detected SIMD Level` = x$runtime_info$detected_simd_level
189-
))
190-
print_key_values("Build", c(
191-
`C++ Library Version` = x$build_info$cpp_version,
192-
`C++ Compiler` = x$build_info$cpp_compiler,
193-
`C++ Compiler Version` = x$build_info$cpp_compiler_version,
194-
`Git ID` = x$build_info$git_id
195-
))
183+
print_key_values(
184+
"Memory",
185+
c(
186+
Allocator = x$memory_pool$backend_name,
187+
# utils:::format.object_size is not properly vectorized
188+
Current = format_bytes(x$memory_pool$bytes_allocated, ...),
189+
Max = format_bytes(x$memory_pool$max_memory, ...)
190+
)
191+
)
192+
print_key_values(
193+
"Runtime",
194+
c(
195+
`SIMD Level` = x$runtime_info$simd_level,
196+
`Detected SIMD Level` = x$runtime_info$detected_simd_level
197+
)
198+
)
199+
print_key_values(
200+
"Build",
201+
c(
202+
`C++ Library Version` = x$build_info$cpp_version,
203+
`C++ Compiler` = x$build_info$cpp_compiler,
204+
`C++ Compiler Version` = x$build_info$cpp_compiler_version,
205+
`Git ID` = x$build_info$git_id
206+
)
207+
)
196208

197209
invisible(x)
198210
}

r/R/arrow-object.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
# under the License.
1717

1818
#' @include enums.R
19-
ArrowObject <- R6Class("ArrowObject",
19+
ArrowObject <- R6Class(
20+
"ArrowObject",
2021
public = list(
2122
initialize = function(xp) self$set_pointer(xp),
2223
pointer = function() get(".:xp:.", envir = self),
2324
`.:xp:.` = NULL,
2425
set_pointer = function(xp) {
2526
if (!inherits(xp, "externalptr")) {
2627
stop(
27-
class(self)[1], "$new() requires a pointer as input: ",
28+
class(self)[1],
29+
"$new() requires a pointer as input: ",
2830
"did you mean $create() instead?",
2931
call. = FALSE
3032
)
@@ -66,7 +68,8 @@ ArrowObject <- R6Class("ArrowObject",
6668
`!=.ArrowObject` <- function(lhs, rhs) !(lhs == rhs) # nolint
6769

6870
#' @export
69-
`==.ArrowObject` <- function(x, y) { # nolint
71+
`==.ArrowObject` <- function(x, y) {
72+
# nolint
7073
x$Equals(y)
7174
}
7275

0 commit comments

Comments
 (0)