1 2#' Create options for an [r_process] object 3#' 4#' @param ... Options to override, named arguments. 5#' @return A list of options. 6#' 7#' `r_process_options()` creates a set of options to initialize a new 8#' object from the `r_process` class. Its arguments must be named, the 9#' names are used as option names. The options correspond to (some of) 10#' the arguments of the [r()] function. At least the `func` option must be 11#' specified, this is the R function to run in the background. 12#' 13#' @export 14#' @examples 15#' ## List all options and their default values: 16#' r_process_options() 17 18r_process_options <- function(...) { 19 update_options(r_process_options_default(), ...) 20} 21 22#' Create options for an [rcmd_process] object 23#' 24#' @param ... Options to override, named arguments. 25#' @return A list of options. 26#' 27#' `rcmd_process_options()` creates a set of options to initialize a new 28#' object from the `rcmd_process` class. Its arguments must be named, the 29#' names are used as option names. The options correspond to (some of) 30#' the arguments of the [rcmd()] function. At least the `cmd` option must 31#' be specified, to select the `R CMD` subcommand to run. Typically 32#' `cmdargs` is specified as well, to supply more arguments to `R CMD`. 33#' 34#' @export 35#' @examples 36#' ## List all options and their default values: 37#' rcmd_process_options() 38 39rcmd_process_options <- function(...) { 40 update_options(rcmd_process_options_default(), ...) 41} 42 43#' Create options for an [rscript_process] object 44#' 45#' @param ... Options to override, named arguments. 46#' @return A list of options. 47#' 48#' `rscript_process_options()` creates a set of options to initialize a new 49#' object from the `rscript_process` class. Its arguments must be named, 50#' the names are used as option names. The options correspond to (some of) 51#' the arguments of the [rscript()] function. At least the `script` option 52#' must be specified, the script file to run. 53#' 54#' @export 55#' @examples 56#' ## List all options and their default values: 57#' rscript_process_options() 58 59rscript_process_options <- function(...) { 60 update_options(rscript_process_options_default(), ...) 61} 62 63r_process_options_default <- function() { 64 list( 65 func = NULL, 66 args = list(), 67 libpath = .libPaths(), 68 repos = default_repos(), 69 stdout = "|", 70 stderr = "|", 71 poll_connection = TRUE, 72 error = getOption("callr.error", "error"), 73 cmdargs = c("--slave", "--no-save", "--no-restore"), 74 system_profile = FALSE, 75 user_profile = "project", 76 env = character(), 77 supervise = FALSE, 78 load_hook = default_load_hook(), 79 extra = list(), 80 package = FALSE, 81 arch = "same" 82 ) 83} 84 85rcmd_process_options_default <- function() { 86 list( 87 cmd = NULL, 88 cmdargs = character(), 89 libpath = .libPaths(), 90 stdout = "|", 91 stderr = "|", 92 poll_connection = TRUE, 93 repos = default_repos(), 94 system_profile = FALSE, 95 user_profile = "project", 96 env = rcmd_safe_env(), 97 wd = ".", 98 supervise = FALSE, 99 extra = list(), 100 arch = "same" 101 ) 102} 103 104rscript_process_options_default <- function() { 105 list( 106 script = NULL, 107 cmdargs = character(), 108 libpath = .libPaths(), 109 stdout = "|", 110 stderr = "|", 111 poll_connection = TRUE, 112 repos = default_repos(), 113 system_profile = FALSE, 114 user_profile = "project", 115 env = rcmd_safe_env(), 116 wd = ".", 117 color = FALSE, 118 extra = list(), 119 arch = "same" 120 ) 121} 122 123update_options <- function(old_opts, ...) { 124 new_opts <- list(...) 125 stopifnot(is.named(new_opts)) 126 check_for_option_names(old_opts, new_opts) 127 utils::modifyList(old_opts, new_opts) 128} 129 130check_for_option_names <- function(old, new) { 131 if (length(miss <- setdiff(names(new), names(old)))) { 132 throw(new_error("Unknown option", if (length(miss) > 1) "s", ":", 133 enumerate(sQuote(miss)))) 134 } 135} 136