Giter Site home page Giter Site logo

Comments (3)

jpryda avatar jpryda commented on August 19, 2024 1

Thanks a lot for the breakdown John! That makes sense now - no peculiar side effects as I had previously thought.

from wrapr.

JohnMount avatar JohnMount commented on August 19, 2024 1

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.

from wrapr.

JohnMount avatar JohnMount commented on August 19, 2024

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:

  • Statement 1 gets substituted as the symbol 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).
  • Statement 2 does not get substituted as 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.
  • As you mentioned Statement 3 and 4 are properly left alone.

Some of the intent and rules of wrapr::let() are documented here.

from wrapr.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.