From 3458d924ca4ebd6c983f2347787ce14078fb5dc6 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Sun, 6 Jul 2014 12:10:51 -0700 Subject: [PATCH] Calling getOption() with default is slow This has a measurable effect in apps with lots of reactives. Reported by Aran Lunzer --- R/graph.R | 2 +- R/imageutils.R | 2 +- R/middleware-shiny.R | 2 +- R/middleware.R | 10 +++++----- R/react.R | 4 ++-- R/server.R | 4 ++-- R/shiny.R | 2 +- R/shinywrappers.R | 2 +- R/utils.R | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/R/graph.R b/R/graph.R index 0ecb669c7..f50c91559 100644 --- a/R/graph.R +++ b/R/graph.R @@ -55,7 +55,7 @@ renderReactLog <- function() { } .graphAppend <- function(logEntry, domain = getDefaultReactiveDomain()) { - if (isTRUE(getOption('shiny.reactlog', FALSE))) + if (isTRUE(getOption('shiny.reactlog'))) .graphEnv$log <- c(.graphEnv$log, list(logEntry)) if (!is.null(domain)) { diff --git a/R/imageutils.R b/R/imageutils.R index 54aa14f3a..d0311b290 100644 --- a/R/imageutils.R +++ b/R/imageutils.R @@ -34,7 +34,7 @@ plotPNG <- function(func, filename=tempfile(fileext='.png'), # Finally, if neither quartz nor Cairo, use png(). if (capabilities("aqua")) { pngfun <- png - } else if (getOption('shiny.usecairo', TRUE) && + } else if ((getOption('shiny.usecairo') %OR% TRUE) && nchar(system.file(package = "Cairo"))) { pngfun <- Cairo::CairoPNG } else { diff --git a/R/middleware-shiny.R b/R/middleware-shiny.R index a0dd7312e..e0022520b 100644 --- a/R/middleware-shiny.R +++ b/R/middleware-shiny.R @@ -5,7 +5,7 @@ reactLogHandler <- function(req) { if (!identical(req$PATH_INFO, '/reactlog')) return(NULL) - if (!getOption('shiny.reactlog', FALSE)) { + if (!isTRUE(getOption('shiny.reactlog'))) { return(NULL) } diff --git a/R/middleware.R b/R/middleware.R index 4c3b7262f..fcf2816ad 100644 --- a/R/middleware.R +++ b/R/middleware.R @@ -281,7 +281,7 @@ HandlerManager <- setRefClass("HandlerManager", createHttpuvApp = function() { list( onHeaders = function(req) { - maxSize <- getOption('shiny.maxRequestSize', 5 * 1024 * 1024) + maxSize <- getOption('shiny.maxRequestSize') %OR% (5 * 1024 * 1024) if (maxSize <= 0) return(NULL) @@ -306,7 +306,7 @@ HandlerManager <- setRefClass("HandlerManager", function (req) { return(handlers$invoke(req)) }, - getOption('shiny.sharedSecret', NULL) + getOption('shiny.sharedSecret') ), onWSOpen = function(ws) { return(wsHandlers$invoke(ws)) @@ -314,7 +314,7 @@ HandlerManager <- setRefClass("HandlerManager", ) }, .httpServer = function(handler, sharedSecret) { - filter <- getOption('shiny.http.response.filter', NULL) + filter <- getOption('shiny.http.response.filter') if (is.null(filter)) filter <- function(req, response) response @@ -329,11 +329,11 @@ HandlerManager <- setRefClass("HandlerManager", response <- handler(req) if (is.null(response)) response <- httpResponse(404, content="

Not Found

") - + if (inherits(response, "httpResponse")) { headers <- as.list(response$headers) headers$'Content-Type' <- response$content_type - + response <- filter(req, response) return(list(status=response$status, body=response$content, diff --git a/R/react.R b/R/react.R index 78d0ec4d9..19365d62b 100644 --- a/R/react.R +++ b/R/react.R @@ -98,7 +98,7 @@ ReactiveEnvironment <- setRefClass( }, currentContext = function() { if (is.null(.currentContext)) { - if (isTRUE(getOption('shiny.suppressMissingContextError', FALSE))) { + if (isTRUE(getOption('shiny.suppressMissingContextError'))) { return(getDummyContext()) } else { stop('Operation not allowed without an active reactive context. ', @@ -138,7 +138,7 @@ ReactiveEnvironment <- setRefClass( reactiveEnvironment <<- ReactiveEnvironment$new() return(reactiveEnvironment) } -}) +}) # Causes any pending invalidations to run. flushReact <- function() { diff --git a/R/server.R b/R/server.R index 671370a5d..7725af752 100644 --- a/R/server.R +++ b/R/server.R @@ -278,7 +278,7 @@ createAppHandlers <- function(httpHandlers, serverFuncSource) { # This value, if non-NULL, must be present on all HTTP and WebSocket # requests as the Shiny-Shared-Secret header or else access will be # denied (403 response for HTTP, and instant close for websocket). - sharedSecret <- getOption('shiny.sharedSecret', NULL) + sharedSecret <- getOption('shiny.sharedSecret') appHandlers <- list( http = joinHandlers(c( @@ -303,7 +303,7 @@ createAppHandlers <- function(httpHandlers, serverFuncSource) { if (is.character(msg)) msg <- charToRaw(msg) - if (getOption('shiny.trace', FALSE)) { + if (isTRUE(getOption('shiny.trace'))) { if (binary) message("RECV ", '$$binary data$$') else diff --git a/R/shiny.R b/R/shiny.R index 23263745a..1a6d7ea01 100644 --- a/R/shiny.R +++ b/R/shiny.R @@ -493,7 +493,7 @@ ShinySession <- setRefClass( if (closed){ return() } - if (getOption('shiny.trace', FALSE)) + if (isTRUE(getOption('shiny.trace'))) message('SEND ', gsub('(?m)base64,[a-zA-Z0-9+/=]+','[base64 data]',json,perl=TRUE)) # first convert to native encoding, then to UTF8, otherwise we may get the diff --git a/R/shinywrappers.R b/R/shinywrappers.R index b9091bbbe..e673a42d4 100644 --- a/R/shinywrappers.R +++ b/R/shinywrappers.R @@ -317,7 +317,7 @@ renderTable <- function(expr, ..., env=parent.frame(), quoted=FALSE, func=NULL) } markRenderFunction(tableOutput, function() { - classNames <- getOption('shiny.table.class', 'data table table-bordered table-condensed') + classNames <- getOption('shiny.table.class') %OR% 'data table table-bordered table-condensed' data <- func() if (is.null(data) || identical(data, data.frame())) diff --git a/R/utils.R b/R/utils.R index e352b0e4a..4b9af8299 100644 --- a/R/utils.R +++ b/R/utils.R @@ -487,7 +487,7 @@ shinyCallingHandlers <- function(expr) { shinyDeprecated <- function(new=NULL, msg=NULL, old=as.character(sys.call(sys.parent()))[1L]) { - if (getOption("shiny.deprecation.messages", default=TRUE) == FALSE) + if (getOption("shiny.deprecation.messages") %OR% TRUE == FALSE) return(invisible()) if (is.null(msg)) {