You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
R uses lexical scoping, which affects how non-local variables of functions are found. Non-local variables are found in the environment where the function was originally defined (parent.env()), not the environment where the function is called (parent.frame()).
f() was defined with Vectorize(), so it has non-local variables SIMPLIFY, USE.NAMES, etc. in its closure. You can verify this with ls(environment(f)). See Hadley's intro to function environments.
In make(), drake creates its own special environment from scratch and assigns all imported functions to that environment. (Otherwise, calls to nested imported functions fail.) Thus, all symbols like SIMPLIFY and USE.NAMES are looked up in an environment different than the original environment(f).
Solution
Sathish solved this specific scenario on StackOverflow. However, this is just one of a handful of edge cases due to the root cause above. To make behavior more predictable, drake needs to stop micromanaging environments and functions altogether and just work in the user's environment. See #37.
The text was updated successfully, but these errors were encountered:
Current behavior
Easy workaround
Enclose your vectorized function in a wrapper function.
Root cause
parent.env()
), not the environment where the function is called (parent.frame()
).f()
was defined withVectorize()
, so it has non-local variablesSIMPLIFY
,USE.NAMES
, etc. in its closure. You can verify this withls(environment(f))
. See Hadley's intro to function environments.make()
, drake creates its own special environment from scratch and assigns all imported functions to that environment. (Otherwise, calls to nested imported functions fail.) Thus, all symbols likeSIMPLIFY
andUSE.NAMES
are looked up in an environment different than the originalenvironment(f)
.Solution
Sathish solved this specific scenario on StackOverflow. However, this is just one of a handful of edge cases due to the root cause above. To make behavior more predictable, drake needs to stop micromanaging environments and functions altogether and just work in the user's environment. See #37.
The text was updated successfully, but these errors were encountered: