tests/testthat/test-clean_variable_names.R

test_that("calls to cleaning variable function are triggered correctly", {
  pattern <- paste(c("\\[", "\\]",
                     "\\{", "\\}",
                     "\\(", "\\)",
                     "[^_^:[:^punct:]]",
                     "\\s+",
                     "\\h+"), collapse = "|")

  expect_equal(clean_variable_names(string_vector = " helloworld",
                                    pattern = pattern),
               "helloworld")

  expect_equal(clean_variable_names(string_vector = "helloworld ",
                                    pattern = pattern),
               "helloworld")

  expect_equal(clean_variable_names(string_vector = " helloworld ",
                                    pattern = pattern),
               "helloworld")

  expect_equal(clean_variable_names(string_vector = "hello world",
                                    pattern = pattern),
               "hello_world")

  expect_equal(clean_variable_names(string_vector = "hello(world",
                                    pattern = pattern),
               "hello_world")

  expect_equal(clean_variable_names(string_vector = "hello (world)",
                                    pattern = pattern),
               "hello__world_")

  expect_equal(clean_variable_names(string_vector = "hello:world",
                                    pattern = pattern),
               "hello:world")
})

Try the predRupdate package in your browser

Any scripts or data that you put into this service are public.

predRupdate documentation built on Sept. 11, 2024, 5:34 p.m.