[R] Lexical scoping/calling stack issue: R fails to recognize an argument's default value

Janko Thyson janko.thyson at gmail.com
Sat Nov 15 01:39:37 CET 2014


Hi Duncan,

thanks for answering and I'm very sorry: I was a bit too quick with letting
the example go.

This should be self-contained now:

require("devtools")

## Dependencies //
devtools::install_github("Rappster/conditionr")
devtools::install_github("Rappster/typr")
devtools::install_github("Rappster/nestr")
devtools::install_github("Rappster/reactr", ref = "bug-28")
## Actual package //
devtools::install_github("Rappster/optionr")
require("optionr")

path <- file.path(tempdir(), "test")
create(path, description = getOption("devtools.desc"), check = FALSE,
  rstudio = TRUE)
setwd(path)

container <- initializeOptionContainer(overwrite = TRUE)
setAnywhereOption(id = "x_1", value = TRUE, reactive = TRUE)
getAnywhereOption(id = "x_1")
setAnywhereOption(id = "x_2",
  value = reactr::reactiveExpression(
    !getAnywhereOption(id = "x_1")
  ),
  reactive = TRUE)

getAnywhereOption(id = "x_1")
getAnywhereOption(id = "x_2")

Thanks a lot should you take the time to look into this,
Janko

On Sat, Nov 15, 2014 at 1:13 AM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

> On 14/11/2014, 6:51 PM, Janko Thyson wrote:
> > Dear list,
> >
> > I just encountered a behavior that I've never seen before:
> >
> > Is it possible, that certain argument names (lazy in my case) are
> > special/reserved and thus would lead to unexpected behavior when a
> calling
> > stack is involved that spreads across functions of three different
> > packages: optionr::setAnywhereOptions() calls nestr::setNested() calls
> > reactr::setShinyReactive()?
>
> No.
>
> >
> > Or is there something I'm generally missing with respect the combination
> of
> > lexical scoping/the frame stack, S4 and default values of function
> > arguments.
> >
> > Running the following code leads to a situation where the default value
> of
> > `lazy` in `reactr::setShinyReactive()` is not properly recognized while
> > others (e.g. `push`) are recognized just fine:
> >
> > require("devtools")
> > devtools::install_github("Rappster/conditionr")
> > devtools::install_github("Rappster/nestr")
> > devtools::install_github("Rappster/optionr")
> > require("optionr")
> >
> > container <- initializeOptionContainer(overwrite = TRUE)
> > expect_true(setAnywhereOption(id = "x_1", value = TRUE, reactive = TRUE))
> > expect_equal(getAnywhereOption(id = "x_1"), TRUE)
> > expect_true(res <- setAnywhereOption(id = "x_2",
> >   value = reactr::reactiveExpression(
> >     !getAnywhereOption(id = "x_1")
> >   ),
> >   reactive = TRUE))
> >
> > The current version of `setShinyReactive()` contains a debugging section
> > that prints these status messages (the actual code:
> > https://github.com/Rappster/reactr/blob/bug-28/R/setShinyReactive.r#L196
> )
> >
> > DEBUG/push/before[1] FALSE
> > DEBUG/lazy/before
> > Error in print(lazy) : argument is missing, with no default
> > DEBUG/is_lazy/before[1] FALSE
> > DEBUG/lazy/after[1] FALSE
> >
> > It also contains my current workaround: also include an argument with
> > name `is_lazy` (whose default)
> > value is recognized again) and then run `lazy <- is_lazy`.
> >
> > You can also find this information in this Stackoverflow post:
> >
> http://stackoverflow.com/questions/26940474/lexical-scoping-issue-r-fails-to-recognize-an-arguments-default-value
> >
> > Thanks a lot for everyone that can shed some light on this!
>
> Sorry, I don't use Stackoverflow.  If you don't get a more useful answer
> from someone else, please simplify the question and post a
> self-contained version to R-help.
>
> Duncan Murdoch
>
> >
> >
> > Best regards,
> > Janko
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list