R/process.R

Defines functions get_username get_gid get_uid id_cmd cmd_output_int cmd_output

#' @export
#' @importFrom processx run
cmd_output <- function(...) {
    result <- run(...)
    result$stdout
}

cmd_output_int <- function(...) {
    compose(as.integer,
            str_trim,
            cmd_stdout)(...)
}

#' @export
#' @importFrom stringr str_trim
id_cmd <- function(...) {
    compose(as.integer,
            str_trim,
            command_output)(command = "id", ...)
}

#' @export
get_uid <- function() {
    id_cmd(args = "-u")
}

#' @export
get_gid <- function() {
    id_cmd(args = "-g")
}

#' @export
get_username <- function() {
    compose(str_trim, system2)("echo", "$USER", stdout = TRUE)
}
aviralg/experimentr documentation built on Jan. 9, 2022, 8:11 a.m.