# 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/AlleloBin")
devtools::load_all()
devtools::document()

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

# Install package locally
devtools::install(upgrade = FALSE, dependencies = FALSE)
# Load and Test
AlleloBin::AlleloBin()

# Optional package check
devtools::check()

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

library(AlleloBin)
options(shiny.fullstacktrace = TRUE)
AlleloBin()

# Build distributable package
# devtools::build_vignettes() # depreciated
pkgbuild::build(vignettes = TRUE)
devtools::build()

# In Terminal setwd("C:/Prasanth/myPrograms/R Programs/2026")
# Use Ctrl+Shift+V
R CMD check --as-cran AlleloBin_1.0.0.tar.gz

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

library(AlleloBin)
AlleloBin()


# Before release
# git add .
# git commit -m "Release v1.0.0"
# git tag v1.0.0

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

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

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

  if (any(grepl("read_one_file", 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")
  }
}


# ======================================================================

cd "C:/Prasanth/myPrograms/R Programs/2026/AlleloBin"
git init
git remote add origin https://github.com/vpprasanth/AlleloBin.git
git add .
git commit -m "Initial release v1.0.0"
git branch -M main
git push -u origin main
