Invocation of the following code has a different binding behavior depending if it's running under shiny or not. I can't justify it in any way.
# app.R
source("b.R")
print("foo after source")
print(foo)
x()
print("setting foo in app.R")
foo <- c(1,2)
x()
# b.R
foo <- c("XXX")
x <- function() {
print("inside function")
print(foo)
}
Result if I invoke it with Rscript:
whatever$ Rscript app.R
[1] "foo after source"
[1] "XXX"
[1] "inside function"
[1] "XXX"
[1] "setting foo in app.R"
[1] "inside function"
[1] 1 2
Result if I invoke it under shiny
> shiny::runApp('whatever')
Loading required package: shiny
[1] "foo after source"
[1] "XXX"
[1] "inside function"
[1] "XXX"
[1] "setting foo in app.R"
[1] "inside function"
[1] "XXX"
It's as if it does early binding for the function closure only when running under shiny.