diff --git a/R/utils.R b/R/utils.R deleted file mode 100644 index 6d95ff1e1..000000000 --- a/R/utils.R +++ /dev/null @@ -1,45 +0,0 @@ -#' Whether the variable name is good to use within Show R Code -#' -#' Spaces are problematic because the variables must be escaped -#' with backticks. -#' Also, they should not start with a number as R may silently make -#' it valid by changing it. -#' Therefore, we only allow alphanumeric characters with underscores. -#' The first character of the `name` must be an alphabetic character -#' and can be followed by alphanumeric characters. -#' -#' @md -#' -#' @param name `character, single or vector` name to check -#' @keywords internal -#' -#' @examples -#' teal.data:::check_simple_name("aas2df") -#' teal.data:::check_simple_name("ADSL") -#' teal.data:::check_simple_name("ADSLmodified") -#' teal.data:::check_simple_name("ADSL_2") -#' teal.data:::check_simple_name("a1") -#' # the following fail -#' \dontrun{ -#' teal.data:::check_simple_name("1a") -#' teal.data:::check_simple_name("ADSL.modified") -#' teal.data:::check_simple_name("ADSL_modified") -#' teal.data:::check_simple_name("a1...") -#' } -check_simple_name <- function(name) { - checkmate::assert_character(name, min.len = 1, any.missing = FALSE) - if (!grepl("^[[:alpha:]][a-zA-Z0-9_]*$", name, perl = TRUE)) { - checkmate::makeAssertion( - name, - paste0( - "'", - name, - "' ", - "must only contain alphanumeric characters (with underscores)", - " and the first character must be an alphabetic character" - ), - var.name = "name", - NULL - ) - } -} diff --git a/man/check_simple_name.Rd b/man/check_simple_name.Rd deleted file mode 100644 index d622b8aaf..000000000 --- a/man/check_simple_name.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{check_simple_name} -\alias{check_simple_name} -\title{Whether the variable name is good to use within Show R Code} -\usage{ -check_simple_name(name) -} -\arguments{ -\item{name}{\verb{character, single or vector} name to check} -} -\description{ -Spaces are problematic because the variables must be escaped -with backticks. -Also, they should not start with a number as R may silently make -it valid by changing it. -Therefore, we only allow alphanumeric characters with underscores. -The first character of the \code{name} must be an alphabetic character -and can be followed by alphanumeric characters. -} -\examples{ -teal.data:::check_simple_name("aas2df") -teal.data:::check_simple_name("ADSL") -teal.data:::check_simple_name("ADSLmodified") -teal.data:::check_simple_name("ADSL_2") -teal.data:::check_simple_name("a1") -# the following fail -\dontrun{ -teal.data:::check_simple_name("1a") -teal.data:::check_simple_name("ADSL.modified") -teal.data:::check_simple_name("ADSL_modified") -teal.data:::check_simple_name("a1...") -} -} -\keyword{internal} diff --git a/tests/testthat/test-check_simple_name.R b/tests/testthat/test-check_simple_name.R deleted file mode 100644 index 693c37139..000000000 --- a/tests/testthat/test-check_simple_name.R +++ /dev/null @@ -1,19 +0,0 @@ -test_that("check_simple_name behaves as expected", { - expect_silent(check_simple_name("aas2df")) - expect_silent(check_simple_name("ADSL")) - expect_silent(check_simple_name("ADSLmodified")) - expect_silent(check_simple_name("a1")) - expect_silent(check_simple_name("ADSL_modified")) - expect_silent(check_simple_name("ADSL_filtered")) - expect_silent(check_simple_name("FILTERED_ADSL")) - expect_silent(check_simple_name("FILTERED")) - expect_silent(check_simple_name("ADSLFILTERED")) - expect_silent(check_simple_name("a_1_2_b_")) - expect_silent(check_simple_name("ADSL_FILTERED")) - - expect_error(check_simple_name("1a")) - expect_error(check_simple_name("ADSL.modified")) - expect_error(check_simple_name("a1...")) - expect_error(check_simple_name("a a")) - expect_error(check_simple_name("_A_b")) -})