Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhardcode timeout in callRemote(), callFun(), showDialog(). Fixes #291. #301

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions R/code.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ getVersion <- function() {
#'
#'
#' @param fname name of the RStudio function to call.
#' @param ... Other arguments passed on to the function
#' @param ... Other arguments passed on to the function.
#' In particular, a `timeout` argument (in seconds) can be specified, by keyword only, for a remote call if running as a job (see `?isJob`).
#' @examples
#'
#' if (rstudioapi::isAvailable()) {
Expand All @@ -90,9 +91,18 @@ getVersion <- function() {
#'
#' @export callFun
callFun <- function(fname, ...) {
args <- list(...)

if (isJob())
return(callRemote(sys.call(), parent.frame()))
if (isJob()) {
if (is.null(args$timeout)) {
return(callRemote(sys.call(),
parent.frame()))
} else {
return(callRemote(sys.call(),
parent.frame(),
timeout = args$timeout))
}
}

verifyAvailable()

Expand All @@ -103,7 +113,6 @@ callFun <- function(fname, ...) {

# drop arguments that aren't accepted by RStudio
# (ensure backwards-compatibility with older versions of RStudio)
args <- list(...)
if (!"..." %in% names(formals(f)))
if (length(args) > length(formals(f)))
length(args) <- length(formals(f))
Expand Down
5 changes: 3 additions & 2 deletions R/dialogs.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#' dialog area. Contents can contain the following HTML tags: "p", "em",
#' "strong", "b" and "i".
#' @param url An optional url to display under the \code{message}.
#' @param timeout Timeout (in seconds) passed to `callFun()` if running as a job (see `?isJob`).
#' @note The \code{showDialog} function was added in version 1.1.67 of RStudio.
#' @export showDialog
showDialog <- function(title, message, url = "") {
callFun("showDialog", title, message, url)
showDialog <- function(title, message, url = "", timeout = 10) {
callFun("showDialog", title, message, url, timeout = timeout)
}


Expand Down
16 changes: 14 additions & 2 deletions R/remote.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ isWorkbenchJob <- function() {
identical(Sys.getenv("RSTUDIO_WORKBENCH_JOB"), "1")
}

callRemote <- function(call, frame) {
#' Make remote call.
#'
#' This function facilitates making a remote call in an RStudio job by serializing
#' the call and its arguments, sending them to the remote environment, and waiting
#' for the response.
#'
#' @param call An unevaluated function call captured by `sys.call()`, representing
#' the original function invocation to be executed remotely.
#' @param frame The environment in which to evaluate the arguments of the `call`.
#' This is typically the parent frame captured by `parent.frame()` in the calling function.
#' @param timeout Timeout (in seconds) if running as a job (see `?isJob`).
#' @return The response from the remote execution of the function call.
callRemote <- function(call, frame, timeout = 10) {

# check for active request / response
requestFile <- Sys.getenv("RSTUDIOAPI_IPC_REQUESTS_FILE", unset = NA)
Expand Down Expand Up @@ -80,7 +92,7 @@ callRemote <- function(call, frame) {

# check for lack of response
diff <- difftime(Sys.time(), now, units = "secs")
if (diff > 10)
if (diff > timeout)
stop("RStudio did not respond to rstudioapi IPC request")

# wait a bit
Expand Down
3 changes: 2 additions & 1 deletion man/callFun.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/callRemote.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/showDialog.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.