dotdot {shinymeta} | R Documentation |
The dot-dot operator
Description
In shinymeta, ..()
is designed for annotating portions of code
inside a metaExpr
(or its higher-level friends metaReactive
,
metaObserve
, and metaRender
). At run time, these meta-
functions search for
..()
calls and replace them with something else (see Details). Outside
of these meta-
functions, ..()
is not defined, so one must take extra care when
interrogating any code within a meta-
function that contains ..()
(see Debugging).
Usage
..(expr)
Arguments
expr |
A single code expression. Required. |
Details
As discussed in the Code Generation
vignette, ..()
is used to mark reactive reads and unquote expressions inside
metaExpr
(or its higher-level friends metaReactive
, metaObserve
, and metaRender
).
The actual behavior of ..()
depends on the current
mode of execution:
-
Normal execution: the
..()
call is stripped from the expression before evaluation. For example,..(dataset())
becomesdataset()
, and..(format(Sys.Date()))
becomesformat(Sys.Date())
. -
Meta execution (as in
expandChain()
): reactive reads are replaced with a suitable name or value (i.e...(dataset())
becomesdataset
or similar) and other code is replaced with its result (..(format(Sys.Date()))
becomes e.g."2019-08-06"
).
Value
expr
, but annotated.
Debugging
If ..()
is called in a context where it isn't defined (that is, outside of a meta-expression),
you'll see an error like: "..() is only defined inside shinymeta meta-expressions".
In practice, this problem can manifest itself in at least 3 different ways:
Execution is halted, perhaps by inserting
browser()
, and from inside theBrowse>
prompt,..()
is called directly. This is also not allowed, because the purpose of..()
is to be searched-and-replaced away beforemetaExpr
begins executing the code. As a result, if you want to interrogate code that contains..()
at theBrowse>
prompt, make sure it's wrapped inmetaExpr
before evaluating it. Also, note that when stepping through ametaExpr
at theBrowse>
prompt withn
, the debugger will echo the actual code that's evaluated during normal execution (i.e.,..()
is stripped), so that's another option for interrogating what happens during normal execution. On the other hand, if you are wanting to interrogate what happens during meta-execution, you can wrap ametaExpr
withexpandChain()
.-
..()
is used in a non-metaExpr
portions ofmetaReactive2
,metaObserve2
, andmetaRender2
. As discussed in The execution model, non-metaExpr
portions of-2
variants always use normal execution and are completely ignored at code generation time, so..()
isn't needed in this context. Crafted a bit of code that uses
..()
in a way that was too clever for shinymeta to understand. For example,lapply(1:5, ..)
is syntactically valid R code, but it's nonsense from a shinymeta perspective.
See Also
metaExpr()
, metaReactive()
, metaObserve()
, metaRender()