<commit_before>reinstall_packages <- function (pkgs = NA) {
    if (is.na(pkgs))
      pkgs <- c(
        "crayon",
        c("dgutil", "github", "dgabbe/dgutil"),
        "directlabels",
        "dplyr",
        "ggplot2",
        "knitr",
        "lubridate",
        "plotrix,"
        "RColorBrewer",
        "readr",
        "readxl",
        "reshape2",
        "rmarkdown",
        "roxygen2",
        "rsconnect",
        "rversions",
        "scales",
        "shiny",
        "stringr",
        "tidyr"
      )

    # Install first so install_github is available.  Don't attach devtools!
    tryCatch(
      {
        p = "devtools"
        find.package(p)
      },
      error = function(e) install.packages(p),
      finally = cat("  ", p, " package installed\n")
    )

    lapply(pkgs, p_install(p))
}

p_install <- function (p) {
  switch(length(p),
         0 = cat("\n    Null string found, skipping"),
         1 = install.packages(p),
         2 = cat("\n   found 2 arguments, expected 1 or 3"),
         3 = switch(p[2],
                    "github" = devtools::install_github(p[3])
                    )
  )
}
<commit_msg>Gets the job done, but needs more refinement.<commit_after>reinstall_packages <- function (pkgs = NA) {
    if (is.na(pkgs))
      pkgs <- c(
        "crayon",
        "dgabbe/dgutil",
        "directlabels",
        "dplyr",
        "ggplot2",
        "knitr",
        "lubridate",
        "plotrix",
        "RColorBrewer",
        "readr",
        "readxl",
        "reshape2",
        "rmarkdown",
        "roxygen2",
        "rsconnect",
        "rversions",
        "scales",
        "shiny",
        "stringr",
        "tidyr"
      )

#    installed <- "Installed: "
    print("Installed:")

    # Install first so install_github() is available.  Don't attach devtools!
    tryCatch(
      {
        p = "devtools"
        find.package(p)
      },
      error = function(e) install.packages(p),
      finally = print(cat("\n  ", p))
    )

    lapply(
      pkgs,
      function (p) {
        if (length(p) == 1) {
          if (grepl("/", p)) {
            try(
              {
                devtools::install_github(p, quiet = TRUE)
                cat("\n  ", p)
              }
            )
          } else
            tryCatch(
              { find.package(p) },
              error = function(e) {
                install.packages(p)
              },
              finally = paste("\n  ", p)
            )
        } else {
          paste("\n   Wrong arguments: ", p)
        }
      }
    )
#  print(installed)
}
{'fraction_non_alphanumeric': 0.1449106449106449, 'fraction_numerical': 0.006216006216006216, 'mean_word_length': 1.3667279411764706, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7523457', 'n_tokens_mistral': 860, 'n_tokens_neox': 829, 'n_words': 166}