build-cran-binaries/R/helpers.R
2024-07-24 18:17:50 +02:00

70 lines
2.1 KiB
R

#' @export
set_codename <- function(codename) {
if (is.null(codename)) {
if (Sys.info()["sysname"] == "Linux") {
dist_fam <- system2("grep",
args = c("'^ID_LIKE=' /etc/os-release | cut -d'=' -f2 | tr -d '\"'"), stdout = TRUE
)
if (dist_fam == "debian") {
codename <- system2("grep",
args = c("'^VERSION_CODENAME=' /etc/os-release | cut -d'=' -f2 | tr -d '\"'"), stdout = TRUE
)
} else if (grepl("rhel", dist_fam)) {
platform_id <- system2("grep",
args = c("'^PLATFORM_ID=' /etc/os-release | cut -d'=' -f2 | tr -d '\"'"), stdout = TRUE
)
if (platform_id == "platform:el9") {
codename <- "rhel9"
} else if (platform_id == "platform:el8") {
codename <- "rhel8"
}
}
} else {
codename <- "unknown"
}
}
return(codename)
}
#' Helper function to set the path for binary package outputs
#' @export
set_bin_path <- function(
r_version_minor, build_for_minor,
local_build_root, codename) {
if (!build_for_minor) {
path <- sprintf(
"%s/__linux__/%s/latest/src/contrib",
local_build_root, codename
)
} else {
path <- sprintf(
"%s/__linux__/%s/%s/latest/src/contrib",
local_build_root, codename, r_version_minor
)
}
cli::cli_alert_warning("DEBUG: path {path}.")
return(path)
}
add_column_if_not_exists <- function(db_name, table_name, column_name, column_type) {
# Connect to the database
conn <- dbConnect(SQLite(), dbname = db_name)
# Get the list of columns in the table
columns <- dbGetQuery(conn, paste0("PRAGMA table_info(", table_name, ");"))
# Check if the column already exists
column_exists <- any(columns$name == column_name)
# Add the column if it doesn't exist
if (!column_exists) {
dbExecute(conn, paste0("ALTER TABLE ", table_name, " ADD COLUMN ", column_name, " ", column_type, ";"))
message(paste("Column '", column_name, "' added to table '", table_name, "'.", sep = ""))
} else {
message(paste("Column '", column_name, "' already exists in table '", table_name, "'.", sep = ""))
}
# Disconnect from the database
dbDisconnect(conn)
}