Skip to content

[Feature Request]: Remove unused functions #196

Description

@averissimo

Feature description

List of unused functions in {teal.transform}:

note: functions being referenced on this list don't necessarily mean that they "should" be removed. They should be assessed case-by-case.

  • call_condition_logical
  • call_condition_range_date
  • call_condition_range_posixct
  • call_extract_array
  • get_initial_filter_values
  • check_data_extract_spec_react
  • extract_choices_labels

Functions only used in @examples

  • call_extract_list
  • call_condition_range
  • call_with_colon

Methods

Functions were detected with script below that uses grep and enhanced with {crayon} for better readability.

🔎 R script
# Get all the functions in the namespace
all_ns <- ls(getNamespace("teal.transform"))

# Get only exported functions
all_exported <- getNamespaceExports("teal.transform")

# Determine S3Methods to exclude
s3_methods <- all_ns |> vapply(isS3method, logical(1)) |> which() |> names()

# Filter out all exported functions and S3 methods
non_exported <- setdiff(setdiff(all_ns, s3_methods), all_exported)

# Use native `grep` to find occurences in source folder
output_path <- withr::local_file("non_exported.txt")

output_con <- file(output_path, open = "wt")

non_exported |> 
  sort() |> 
  purrr::walk(
    function(x) {
      writeLines("----------------------------------", output_con)
      writeLines("", output_con)
      writeLines("", output_con)
      writeLines(glue::glue("    {x}    "), output_con)
      writeLines("", output_con)
      writeLines("", output_con)
      
      result <- system2(
        "grep",
        c(
          "-n",
          glue::glue("\"{x}\""),
          "-R R/ tests/ vignettes/ data-raw/ inst/"
        ),
        stdout = TRUE
      ) |> 
        stringr::str_replace_all(
          glue::glue(":(.+?){x}(.+)"), 
          glue::glue(":\\1", crayon::red(x), "\\2")
        ) |> 
        stringr::str_replace_all(
          "^(.+?):([0-9]+):", 
          glue::glue(crayon::green("\\1"), ":", crayon::magenta("\\2"), ":")
        ) 
      
      writeLines(result, output_con)
      flush(output_con)
    }
  )
close(output_con)
readLines(output_path) |> cat(sep = "\n")

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions