Skip to content

Commit 3747a29

Browse files
koujonkeane
andauthored
GH-46645: [CI][Dev][R] Use pre-commit for styler (#46664)
### Rationale for this change We want to migrate to pre-commit from `archery lint`. ### What changes are included in this PR? Use pre-commit for styler against `r/`. This also fixes styles of exiting files. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #46645 Lead-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Co-authored-by: Jonathan Keane <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 680978f commit 3747a29

File tree

11 files changed

+31
-35
lines changed

11 files changed

+31
-35
lines changed

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ repos:
201201
pass_filenames: false
202202
files: >-
203203
^r/.*\.(R|Rmd)$
204+
- repo: local
205+
hooks:
206+
- id: styler
207+
alias: r
208+
name: R Format
209+
language: r
210+
additional_dependencies:
211+
- roxygen2
212+
- styler
213+
entry: |
214+
Rscript -e "styler::style_file(commandArgs(TRUE)[1])"
215+
files: >-
216+
^r/.*\.(R|Rmd)$
204217
- repo: https://github.com/pre-commit/mirrors-clang-format
205218
rev: v14.0.6
206219
hooks:

r/.styler_excludes.R

Lines changed: 0 additions & 18 deletions
This file was deleted.

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-
R -s -e 'setwd(".."); if (requireNamespace("styler")) styler::style_file(setdiff(system("git diff --name-only | grep r/.*R$$", intern = TRUE), file.path("r", source("r/.styler_excludes.R")$$value)))'
23+
pre-commit run --show-diff-on-failure --color=always styler
2424

2525
style-all:
26-
R -s -e 'styler::style_file(setdiff(dir(pattern = "R$$", recursive = TRUE), source(".styler_excludes.R")$$value))'
26+
pre-commit run --show-diff-on-failure --color=always --all-files styler
2727

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

r/R/filesystem.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ default_s3_options <- list(
493493
#' @examplesIf FALSE
494494
#' # Turn on debug logging. The following line of code should be run in a fresh
495495
#' # R session prior to any calls to `s3_bucket()` (or other S3 functions)
496-
#' Sys.setenv("ARROW_S3_LOG_LEVEL"="DEBUG")
496+
#' Sys.setenv("ARROW_S3_LOG_LEVEL" = "DEBUG")
497497
#' bucket <- s3_bucket("voltrondata-labs-datasets")
498498
#'
499499
#' @export
@@ -554,7 +554,9 @@ GcsFileSystem <- R6Class("GcsFileSystem",
554554
# Convert from nanoseconds to POSIXct w/ UTC tz
555555
if ("expiration" %in% names(out)) {
556556
out$expiration <- as.POSIXct(
557-
out$expiration / 1000000000, origin = "1970-01-01", tz = "UTC"
557+
out$expiration / 1000000000,
558+
origin = "1970-01-01",
559+
tz = "UTC"
558560
)
559561
}
560562

@@ -609,8 +611,10 @@ GcsFileSystem$create <- function(anonymous = FALSE, retry_limit_seconds = 15, ..
609611
stop(
610612
paste(
611613
"Option 'expiration' must be of class POSIXct, not",
612-
class(options$expiration)[[1]]),
613-
call. = FALSE)
614+
class(options$expiration)[[1]]
615+
),
616+
call. = FALSE
617+
)
614618
}
615619

616620
options$retry_limit_seconds <- retry_limit_seconds

r/tests/testthat/helper-skip.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,15 @@ process_is_running <- function(x) {
140140
if (tolower(Sys.info()[["sysname"]]) == "windows") {
141141
# Batch scripts (CMD.exe) doesn't provide a command that shows the original
142142
# call arguments, which we need for testbench since it's launched from Python.
143-
inner_cmd <- paste("WMIC path win32_process get Commandline",
144-
sprintf("| Select-String %s", x),
145-
"| Select-String powershell.exe -NotMatch")
143+
inner_cmd <- paste(
144+
"WMIC path win32_process get Commandline",
145+
sprintf("| Select-String %s", x),
146+
"| Select-String powershell.exe -NotMatch"
147+
)
146148
cmd <- sprintf("powershell -command \"%s\"", inner_cmd)
147149
tryCatch(length(system(cmd, intern = TRUE, show.output.on.console = FALSE)) > 0,
148-
error = function(e) FALSE)
150+
error = function(e) FALSE
151+
)
149152
} else {
150153
cmd <- sprintf("ps aux | grep '%s' | grep -v grep", x)
151154
tryCatch(system(cmd, ignore.stdout = TRUE) == 0, error = function(e) FALSE)

r/tests/testthat/test-Table.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ test_that("as_arrow_table() errors on data.frame with NULL names", {
708708
})
709709

710710
test_that("# GH-35038 - passing in multiple arguments doesn't affect return type", {
711-
712711
df <- data.frame(x = 1)
713712
out1 <- as.data.frame(arrow_table(df, name = "1"))
714713
out2 <- as.data.frame(arrow_table(name = "1", df))

r/tests/testthat/test-dataset-json.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ skip_if_not_available("dataset")
2020
library(dplyr, warn.conflicts = FALSE)
2121

2222
test_that("JSON dataset", {
23-
2423
# set up JSON directory for testing
2524
json_dir <- make_temp_dir()
2625

@@ -66,5 +65,4 @@ test_that("JSON Fragment scan options", {
6665
expect_equal(options$type, "json")
6766

6867
expect_error(FragmentScanOptions$create("json", invalid_selection = TRUE), regexp = "invalid_selection")
69-
7068
})

r/tests/testthat/test-dplyr-funcs-type.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ test_that("as.factor()/dictionary_encode()", {
675675
})
676676

677677
test_that("bad explicit type conversions with as.*()", {
678-
679678
# Arrow returns lowercase "true", "false" (instead of "TRUE", "FALSE" like R)
680679
expect_error(
681680
compare_dplyr_binding(

r/tests/testthat/test-parquet.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ test_that("Can read Parquet files from a URL", {
483483
})
484484

485485
test_that("thrift string and container size can be specified when reading Parquet files", {
486-
487486
tf <- tempfile()
488487
on.exit(unlink(tf))
489488
table <- arrow_table(example_data)

r/tests/testthat/test-schema.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,4 @@ test_that("schema print truncation", {
330330
print_schema_fields(schema(tbl), truncate = TRUE, max_fields = 0),
331331
regexp = "max_fields not greater than 0"
332332
)
333-
334333
})

0 commit comments

Comments
 (0)