Skip to content

Commit b55d0c5

Browse files
Feature/remove tibble (#435)
* Bump R version to allow usage of |> * Fix tibble usage in cran-compliance * Fix find_exports * Fix sanitize code * Fix function options * Draft NEWS * Drop {tibble} dependency * Record PR in docs * Lint * Update Rtools versions * Use Rtools 45
1 parent 0c61cfd commit b55d0c5

File tree

10 files changed

+85
-80
lines changed

10 files changed

+85
-80
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
config:
24-
- {os: windows-latest, r: 'release', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu' }
25-
- {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu' }
26-
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '43' }
24+
- {os: windows-latest, r: 'release', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '45' }
25+
- {os: windows-latest, r: 'devel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '45' }
26+
- {os: windows-latest, r: 'oldrel', rust-version: 'stable-msvc', rust-target: 'x86_64-pc-windows-gnu', rtools-version: '44' }
2727

2828
- {os: macOS-latest, r: 'release', rust-version: 'stable' }
2929

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ License: MIT + file LICENSE
3737
URL: https://extendr.github.io/rextendr/
3838
BugReports: https://github.com/extendr/rextendr/issues
3939
Depends:
40-
R (>= 4.0)
40+
R (>= 4.1)
4141
Imports:
4242
brio,
4343
callr,
@@ -51,7 +51,6 @@ Imports:
5151
rlang (>= 1.0.5),
5252
rprojroot,
5353
stringi,
54-
tibble,
5554
vctrs,
5655
withr
5756
Suggests:

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* Added `read_cargo_metadata()` to retrieve Cargo metadata for packages and
2929
workspaces. (#389)
3030
* `rustup_sitrep()` now checks if a default toolchain has been set. <https://github.com/extendr/rextendr/pull/416>
31+
* Minimum R version is set to `4.1` (#435)
32+
* `{tibble}` is no longer a dependency (#435)
3133

3234
# rextend 0.3.1
3335

R/cran-compliance.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ vendor_pkgs <- function(path = ".", quiet = FALSE, overwrite = NULL) {
8181
}
8282

8383
# create a dataframe of vendored crates
84-
vendored <- vendor_res[["stderr"]] %>%
85-
cli::ansi_strip() %>%
84+
vendored <- vendor_res[["stderr"]] |>
85+
cli::ansi_strip() |>
8686
stringi::stri_split_lines1()
8787

88-
res <- stringi::stri_match_first_regex(vendored, "Vendoring\\s([A-z0-9_][A-z0-9_-]*?)\\s[vV](.+?)(?=\\s)") %>%
89-
tibble::as_tibble(.name_repair = "minimal") %>%
90-
rlang::set_names(c("source", "crate", "version")) %>%
91-
dplyr::filter(!is.na(source)) %>%
92-
dplyr::select(-source) %>%
88+
res <- stringi::stri_match_first_regex(vendored, "Vendoring\\s([A-z0-9_][A-z0-9_-]*?)\\s[vV](.+?)(?=\\s)") |>
89+
as.data.frame() |>
90+
rlang::set_names(c("source", "crate", "version")) |>
91+
dplyr::filter(!is.na(source)) |>
92+
dplyr::select(-source) |>
9393
dplyr::arrange(.data$crate)
9494

9595
# capture vendor-config.toml content
96-
config_toml <- vendor_res[["stdout"]] %>%
97-
cli::ansi_strip() %>%
96+
config_toml <- vendor_res[["stdout"]] |>
97+
cli::ansi_strip() |>
9898
stringi::stri_split_lines1()
9999

100100
# always write to file as cargo vendor catches things like patch.crates-io

R/find_exports.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ find_exports <- function(clean_lns) {
55

66
# start and end may empty
77
if (rlang::is_empty(start) || rlang::is_empty(end)) {
8-
return(tibble::tibble(name = character(0), type = character(0), lifetime = character(0)))
8+
return(data.frame(name = character(0), type = character(0), lifetime = character(0)))
99
}
1010

11-
map2(start, end, ~ extract_meta(clean_lns[.x:.y])) %>%
12-
discard(~ is.na(.x["impl"]) & is.na(.x["fn"])) %>%
13-
dplyr::bind_rows() %>%
14-
dplyr::mutate(type = dplyr::coalesce(.data$impl, .data$fn)) %>%
11+
map2(start, end, \(.x, .y) extract_meta(clean_lns[.x:.y])) |>
12+
discard(\(.x) is.na(.x["impl"]) & is.na(.x["fn"])) |>
13+
dplyr::bind_rows() |>
14+
dplyr::mutate(type = dplyr::coalesce(.data$impl, .data$fn)) |>
1515
dplyr::select(dplyr::all_of(c("name", "type", "lifetime")))
1616
}
1717

@@ -27,9 +27,9 @@ extract_meta <- function(lns) {
2727
result <- stringi::stri_match_first_regex(
2828
glue_collapse(lns, sep = "\n"),
2929
"(?:(?<struct>struct)|(?<enum>enum)|(?<fn>fn)|(?<impl>impl)(?:\\s*<(?<lifetime>.+?)>)?)\\s+(?<name>(?:r#)?(?:_\\w+|[A-z]\\w*))" # nolint: line_length_linter
30-
) %>%
31-
tibble::as_tibble(.name_repair = "minimal") %>%
32-
rlang::set_names(c("match", "struct", "enum", "fn", "impl", "lifetime", "name")) %>%
30+
) |>
31+
as.data.frame() |>
32+
rlang::set_names(c("match", "struct", "enum", "fn", "impl", "lifetime", "name")) |>
3333
dplyr::filter(!is.na(.data$match))
3434

3535
# If no matches have been found, then the attribute is misplaced

R/function_options.R

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
extendr_function_config <- rlang::env(
2-
known_options = tibble::tribble(
3-
~Name, ~Ptype,
4-
"r_name", character(),
5-
"mod_name", character(),
6-
"use_rng", logical()
2+
known_options = data.frame(
3+
Name = c("r_name", "mod_name", "use_rng"),
4+
Ptype = I(list(
5+
character(),
6+
character(),
7+
logical()
8+
))
79
)
810
)
911

@@ -14,7 +16,7 @@ extendr_function_config <- rlang::env(
1416
#' @noRd
1517
convert_function_options <- function(options, suppress_warnings) {
1618
if (rlang::is_null(options) || rlang::is_empty(options)) {
17-
return(tibble::tibble(Name = character(), RustValue = character()))
19+
return(data.frame(Name = character(), RustValue = character()))
1820
}
1921

2022
if (!rlang::is_list(options) || !rlang::is_named(options)) {
@@ -24,25 +26,25 @@ convert_function_options <- function(options, suppress_warnings) {
2426
)
2527
}
2628

27-
options_table <- tibble::tibble(Name = rlang::names2(options), Value = unname(options)) %>%
28-
dplyr::left_join(extendr_function_config$known_options, by = "Name") %>%
29+
options_table <- data.frame(Name = rlang::names2(options), Value = I(unname(options))) |>
30+
dplyr::left_join(extendr_function_config$known_options, by = "Name") |>
2931
dplyr::mutate(
3032
Value = pmap(
3133
list(.data$Value, .data$Ptype, .data$Name),
32-
~ if (rlang::is_null(..2)) ..1 else vctrs::vec_cast(..1, ..2, x_arg = ..3)
34+
\(...) if (rlang::is_null(..2)) ..1 else vctrs::vec_cast(..1, ..2, x_arg = ..3)
3335
),
3436
)
3537

36-
unknown_option_names <- options_table %>%
37-
dplyr::filter(map_lgl(.data$Ptype, rlang::is_null)) %>%
38+
unknown_option_names <- options_table |>
39+
dplyr::filter(map_lgl(.data$Ptype, rlang::is_null)) |>
3840
dplyr::pull(.data$Name)
3941

40-
invalid_options <- options_table %>%
42+
invalid_options <- options_table |>
4143
dplyr::mutate(
4244
IsNameInvalid = !is_valid_rust_name(.data$Name),
4345
IsValueNull = map_lgl(.data$Value, rlang::is_null),
4446
IsNotScalar = !.data$IsValueNull & !map_lgl(.data$Value, vctrs::vec_is, size = 1L)
45-
) %>%
47+
) |>
4648
dplyr::filter(
4749
.data$IsNameInvalid | .data$IsValueNull | .data$IsNotScalar
4850
)
@@ -56,7 +58,7 @@ convert_function_options <- function(options, suppress_warnings) {
5658
))
5759
}
5860

59-
options_table %>%
61+
options_table |>
6062
dplyr::transmute(
6163
.data$Name,
6264
RustValue = map_chr(.data$Value, convert_option_to_rust)
@@ -70,18 +72,18 @@ convert_function_options <- function(options, suppress_warnings) {
7072
cli_abort_invalid_options <- function(invalid_options) {
7173
n_invalid_opts <- vctrs::vec_size(invalid_options) # nolint: object_usage_linter
7274

73-
invalid_names <- invalid_options %>% get_option_names(.data$IsNameInvalid)
74-
null_values <- invalid_options %>% get_option_names(.data$IsValueNull)
75-
vector_values <- invalid_options %>% get_option_names(.data$IsNotScalar)
75+
invalid_names <- invalid_options |> get_option_names(.data$IsNameInvalid)
76+
null_values <- invalid_options |> get_option_names(.data$IsValueNull)
77+
vector_values <- invalid_options |> get_option_names(.data$IsNotScalar)
7678

7779
message <- c(
7880
"Found {.val {n_invalid_opts}} invalid {.code extendr} function option{?s}:",
79-
x = "Unsupported name{?s}: {.val {invalid_names}}." %>% if_any_opts(invalid_names),
80-
x = "Null value{?s}: {.val {null_values}}." %>% if_any_opts(null_values),
81-
x = "Vector value{?s}: {.val {vector_values}}." %>% if_any_opts(vector_values),
82-
i = "Option names should be valid rust names." %>% if_any_opts(invalid_names),
83-
i = "{.code NULL} values are disallowed." %>% if_any_opts(null_values),
84-
i = "Only scalars are allowed as option values." %>% if_any_opts(vector_values)
81+
x = "Unsupported name{?s}: {.val {invalid_names}}." |> if_any_opts(invalid_names),
82+
x = "Null value{?s}: {.val {null_values}}." |> if_any_opts(null_values),
83+
x = "Vector value{?s}: {.val {vector_values}}." |> if_any_opts(vector_values),
84+
i = "Option names should be valid rust names." |> if_any_opts(invalid_names),
85+
i = "{.code NULL} values are disallowed." |> if_any_opts(null_values),
86+
i = "Only scalars are allowed as option values." |> if_any_opts(vector_values)
8587
)
8688

8789
cli::cli_abort(message, class = "rextendr_error")
@@ -93,8 +95,8 @@ cli_abort_invalid_options <- function(invalid_options) {
9395
#' @return A character vector of option names.
9496
#' @noRd
9597
get_option_names <- function(invalid_options, filter_column) {
96-
invalid_options %>%
97-
dplyr::filter({{ filter_column }}) %>%
98+
invalid_options |>
99+
dplyr::filter({{ filter_column }}) |>
98100
dplyr::pull(.data$Name)
99101
}
100102

R/sanitize_code.R

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
sanitize_rust_code <- function(lines) {
2-
lines %>%
3-
remove_empty_or_whitespace() %>%
4-
fill_block_comments() %>%
5-
remove_line_comments() %>%
2+
lines |>
3+
remove_empty_or_whitespace() |>
4+
fill_block_comments() |>
5+
remove_line_comments() |>
66
remove_empty_or_whitespace()
77
}
88

@@ -34,16 +34,18 @@ fill_block_comments <- function(lns, fill_with = " ") { # nolint: object_usage_l
3434

3535
# A sorted DF having `start`, `end`, and `type`
3636
comment_syms <-
37-
locations %>%
38-
map(tibble::as_tibble) %>%
37+
locations |>
38+
map(as.data.frame) |>
3939
imap(
40-
~ dplyr::mutate(
41-
.x,
42-
type = dplyr::if_else(.y == 1L, "open", "close")
43-
)
44-
) %>%
45-
dplyr::bind_rows() %>%
46-
dplyr::filter(!is.na(.data$start)) %>%
40+
\(.x, .y) {
41+
dplyr::mutate(
42+
.x,
43+
type = dplyr::if_else(.y == 1L, "open", "close")
44+
)
45+
}
46+
) |>
47+
dplyr::bind_rows() |>
48+
dplyr::filter(!is.na(.data$start)) |>
4749
dplyr::arrange(.data$start)
4850

4951
# Fast path if no comments are found at all.
@@ -98,10 +100,10 @@ fill_block_comments <- function(lns, fill_with = " ") { # nolint: object_usage_l
98100
# and the next delimiter starts the new block, so we include both, as well as
99101
# the first in the table.
100102
to_replace <-
101-
valid_syms %>%
103+
valid_syms |>
102104
dplyr::mutate(
103105
cnt = cumsum(dplyr::if_else(.data$type == "open", +1L, -1L))
104-
) %>%
106+
) |>
105107
dplyr::filter(
106108
dplyr::lag(.data$cnt) == 0 | .data$cnt == 0 | dplyr::row_number() == 1
107109
)
@@ -127,9 +129,9 @@ fill_block_comments <- function(lns, fill_with = " ") { # nolint: object_usage_l
127129
)
128130
}
129131
# Manual `pivot_wider`.
130-
to_replace <- tibble::tibble(
132+
to_replace <- data.frame(
131133
start_open = dplyr::filter(to_replace, .data$type == "open")[["start"]],
132-
end_close = dplyr::filter(to_replace, .data$type == "close")[["end"]],
134+
end_close = dplyr::filter(to_replace, .data$type == "close")[["end"]]
133135
)
134136

135137
# Replaces each continuous commnet block with whitespaces

R/source.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ invoke_cargo <- function(toolchain, specific_target, dir, profile,
316316

317317
minor_patch <- package_version(R.version$minor)
318318

319-
if (minor_patch >= "4.0") {
319+
if (minor_patch >= "5.0") {
320+
rtools_version <- "45" # nolint: object_usage_linter
321+
} else if (minor_patch >= "4.0") {
320322
rtools_version <- "44" # nolint: object_usage_linter
321323
} else if (minor_patch >= "3.0") {
322324
rtools_version <- "43" # nolint: object_usage_linter

tests/testthat/_snaps/cran-compliance.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414
Code
1515
package_versions
1616
Output
17-
# A tibble: 10 x 2
18-
crate version
19-
<chr> <chr>
20-
1 build-print *.*.*
21-
2 extendr-api *.*.*
22-
3 extendr-ffi *.*.*
23-
4 extendr-macros *.*.*
24-
5 once_cell *.*.*
25-
6 paste *.*.*
26-
7 proc-macro2 *.*.*
27-
8 quote *.*.*
28-
9 syn *.*.*
29-
10 unicode-ident *.*.*
17+
crate version
18+
1 build-print *.*.*
19+
2 extendr-api *.*.*
20+
3 extendr-ffi *.*.*
21+
4 extendr-macros *.*.*
22+
5 once_cell *.*.*
23+
6 paste *.*.*
24+
7 proc-macro2 *.*.*
25+
8 quote *.*.*
26+
9 syn *.*.*
27+
10 unicode-ident *.*.*
3028

tests/testthat/test-make-module-macro.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ test_that("Rust metadata capturing", {
148148

149149
expect_equal(
150150
extract_meta("#[extendr] pub \tfn\t test_fn \t() {}"),
151-
tibble::tibble(
151+
data.frame(
152152
match = "fn\t test_fn",
153153
struct = NA_character_,
154154
enum = NA_character_,
@@ -164,7 +164,7 @@ test_that("Rust metadata capturing", {
164164
"#[extendr]",
165165
"pub impl <'a, \t 'b> X <a', 'b> {}"
166166
)),
167-
tibble::tibble(
167+
data.frame(
168168
match = "impl <'a, \t 'b> X",
169169
struct = NA_character_,
170170
enum = NA_character_,

0 commit comments

Comments
 (0)