# Install fs if you don't have it yet
# if (!requireNamespace("fs", quietly = TRUE)) install.packages("fs")

# Print the folder tree
fs::dir_tree(getwd())

# Delete the NAMESPACE file in the current working directory
if (file.exists("NAMESPACE")) {
  file.remove("NAMESPACE")
  cat("NAMESPACE file successfully removed.\n")
} else {
  cat("NAMESPACE file not found.\n")
}

# Development & generate documentation
# setwd("C:/Prasanth/myPrograms/R Programs/2026/ALS_Binary")
devtools::load_all()
devtools::document()

# Delete the ALSBinary package
# Delete the ALSBinary package safely
if (system.file(package = "ALSBinary") != "") {
    remove.packages("ALSBinary")
    cat("ALSBinary package successfully removed.\n")
} else {
    cat("ALSBinary package not found.\n")
}
# Restart R
rstudioapi::executeCommand("restartR")


# Install package locally
devtools::install(upgrade = FALSE, dependencies = FALSE)
# Load and Test
library(ALSBinary)
ALSBinary::run_app() # Or
# ALSBinary::als_binary() # Or
# ALSBinary::runALSBinaryApp()


# Optional package check
devtools::check()

# Fresh-session test: Restart R:
rstudioapi::executeCommand("restartR")


library(ALSBinary)
options(shiny.fullstacktrace = TRUE)
als_binary()

# Renders the vignettes to a local doc/ website for immediate visual preview
pkgdown::build_articles()
devtools::build()

# Optionally test in a clean session:
install.packages(
  "ALSBinary_1.0.0.tar.gz",
  repos = NULL,
  type = "source"
)

library(ALSBinary)
ALSBinary::run_app() # Or
# ALSBinary::als_binary() # Or
# ALSBinary::runALSBinaryApp()


# Before release
# git init
# git add .
# git commit -m "Release v1.0.0"
# git tag v1.0.0
# git remote add origin https://github.com/vpprasanth/ALS_Binary.git


# Search the keyword, "setNames":
grep(
  "setNames",
  unlist(
    lapply(
      list.files("R", full.names = TRUE),
      readLines
    )
  ),
  value = TRUE
)

#------------------
# search the file itself for the keyword, "readxlsb"
rfiles <- list.files("R", full.names = TRUE)

for (f in rfiles) {
  txt <- readLines(f, warn = FALSE)

  if (any(grepl("readxlsb", txt, fixed = TRUE))) {
    cat("FOUND IN:", f, "\n")
  }
}

#---------------------------------------------------------------------
# Find all files recursively across all subfolders
all_files <- list.files(path = ".", recursive = TRUE, full.names = TRUE)

# Loop through every file to search for the keyword
for (f in all_files) {
  # Skip directories if they accidentally get listed
  if (dir.exists(f)) next

  # Read file safely
  txt <- readLines(f, warn = FALSE)

  # Check for the specific keyword
  if (any(grepl("DataSpecsReviewer", txt, fixed = TRUE))) {
    cat("FOUND IN:", f, "\n")
  }
}
