Closed jpryda closed 6 years ago
Actually wrapr
is working as intended on the example. Probably not doing what you want, but you may be able to work into it if you are interested.
Here is your example with debugging turned on.
reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-11-13
library("wrapr")
packageVersion("wrapr")
#> [1] '1.0.1'
params.list <- list(
MQT_TBL_1_ = 'dir_p_pts',
MQT_AGG_TYPE_ = 'max'
)
applyAgg <- function(params.list.agg){
wrapr::let(
alias=list(MQT_TBL_1_=params.list.agg$MQT_TBL_1_),
expr={
print(params.list.agg$MQT_TBL_1_) # This doesn't work (aliased)
print(params.list.agg[["MQT_TBL_1_"]]) # This does work (aliased)
print(params.list.agg$MQT_AGG_TYPE_) # This does work (not aliased)
print(params.list.agg[["MQT_AGG_TYPE_"]]) # This does work (not aliased)
},
debugPrint = TRUE)
}
applyAgg(params.list)
#> $MQT_TBL_1_
#> [1] "dir_p_pts"
#>
#> {
#> print(params.list.agg$dir_p_pts)
#> print(params.list.agg[["MQT_TBL_1_"]])
#> print(params.list.agg$MQT_AGG_TYPE_)
#> print(params.list.agg[["MQT_AGG_TYPE_"]])
#> }
#> NULL
#> [1] "dir_p_pts"
#> [1] "max"
#> [1] "max"
I've modified wrapr
's debug mode to print the alias map in addition to the substituted expression.
wrapr::let()
is designed to substitute code symbols (explicit variables and names of columns) for other symbols.
Notice that wrapr::let()
only performed a substitution in the first of the four statements.
The rules detailed are:
MQT_TBL_1_
is seen as a code entity (the right-hand-side of a $
operator, I think this is actually a special case in wrapr
due to some details of how R
code is represented).wrapr
does not perceive the "MQT_TBL_1_"
as a bit of code, but instead as a constant. It might be argued we would want to special case this as we did with $
, but that would be a bit more difficult.Some of the intent and rules of wrapr::let()
are documented here.
Thanks a lot for the breakdown John! That makes sense now - no peculiar side effects as I had previously thought.
Glad that helped! The substitution stuff can get confusing. Your question gave me the idea of printing more in the debug so one can see what is going on. Like the idea of "breakdown" slowing things down enough so one can see the steps.
There seems to be inconsistency in referencing named items in a list passed in as a parameter: