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

Update: Closes #98 removing symbols that are no longer illegal #119

Merged
merged 6 commits into from
May 24, 2023
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
2 changes: 1 addition & 1 deletion R/utils-xportr.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ xpt_validate <- function(data) {
}

# 2.2 Check Non-ASCII and special characters
chk_spl_chr <- labels[stringr::str_detect(labels, "[<>]|[^[:ascii:]]")]
chk_spl_chr <- labels[stringr::str_detect(labels, "[^[:ascii:]]")]

if (length(chk_spl_chr) > 0) {
err_cnd <- c(
Expand Down
2 changes: 1 addition & 1 deletion R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ xportr_write <- function(.df, path, label = NULL, strict_checks = FALSE) {
abort("`label` must be 40 characters or less.")
}

if (stringr::str_detect(label, "[<>]|[^[:ascii:]]")) {
if (stringr::str_detect(label, "[^[:ascii:]]")) {
abort("`label` cannot contain any non-ASCII, symbol or special characters.")
}

Expand Down
18 changes: 9 additions & 9 deletions tests/testthat/test-utils-xportr.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ test_that("xpt_validate_var_names: Get error message when tje variable contains
)
})

test_that("xpt_validate: Get error message when the label contains non-ASCII, symbol or special characters", {
df <- data.frame(A = 1, B = 2)
attr(df$A, "label") <- "foo<bar"
expect_equal(
xpt_validate(df),
"Label 'A=foo<bar' cannot contain any non-ASCII, symbol or special characters."
)
})

test_that("xpt_validate: Get error message when the label contains over 40 characters", {
df <- data.frame(A = 1, B = 2)
long_label <- paste(rep("a", 41), collapse = "")
Expand All @@ -101,3 +92,12 @@ test_that("xpt_validate: Get error message when the variable type is invalid", {
"Variables `A` and `B` must have a valid type."
)
})

test_that("xpt_validate: Get error message when the label contains non-ASCII, symbol or special characters", {
df <- data.frame(A = 1, B = 2)
attr(df$A, "label") <- "fooçbar"
expect_equal(
xpt_validate(df),
"Label 'A=fooçbar' cannot contain any non-ASCII, symbol or special characters."
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test_that("xportr_write: expect error when label contains non-ASCII symbols or s

on.exit(unlink(tmpdir))

expect_error(xportr_write(data_to_save, tmp, label = "<test>"))
expect_error(xportr_write(data_to_save, tmp, label = "çtestç"))
})

test_that("xportr_write: expect error when label is over 40 characters", {
Expand Down