Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[named_region] add checks for named region string. closes #1095 #1097

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -9395,6 +9395,9 @@ wbWorkbook <- R6::R6Class(
) {
name <- replace_legal_chars(name)

if (!grepl("^[\\p{L}_][^\\s]*$", name, perl = TRUE))
stop("named region must begin with a letter or an underscore and not contain whitespace(s).")

# special names

## print
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-named_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,13 @@ test_that("local_sheet works", {
expect_equal(exp, got)

})

test_that("named region checks work", {
wb <- wb_workbook()$add_worksheet()

expect_error(wb$add_named_region(dims = "A1", name = 1), "letter or an underscore")
expect_error(wb$add_named_region(dims = "B1", name = "1"), "letter or an underscore")
expect_silent(wb$add_named_region(dims = "C1", name = stringi::stri_unescape_unicode("\\u00e4")))
expect_error(wb$add_named_region(dims = "D1", name = "a b"), "letter or an underscore")
expect_error(wb$add_named_region(dims = "D1", name = "A1"), "cell reference")
})
Loading