"Loop Attributes - Expression Evaluation Error"

1705410G
1705410G New Altair Community Member
edited November 2024 in Community Q&A
I'm using 2 separate Loop Attributes Operator, each containing a Generate Attribute Operator.

Attribute Name(Inside Generate Attribute) for both Loop Attributes Operator: %{loop_attribute}


However, this error popped out. 
Expression Evaluation Error: The function 'eval' failed to parse the subexpression '203_10'. Cause: token recognition error at '_'  .
Initially, I thought that by removing the underscore '_' will solve it. But no matter what I did to rename it using the Rename by Replacing operator, it doesn't work. Same error comes up.



Sometimes, the Not Enough Iterations Error  pops up as well. I'm confused when I have set the Loop Attribute to subset and have selected the necessary attributes. 

Regards,
AY

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answers

  • David_A
    David_A New Altair Community Member
    Answer ✓
    Hi,

    the problem here is how macros are parsed.
    In your case, first %{loop_attribute} is replaced with the attribute name, this is "2_speed". Then the eval() function tries to make sense of that string as a number or mathematical expression, what fails.

    In that case you need to use the seldom used #{loot_attribute} syntax. This returns the value corresponding to that attribute name.

    @mschmitz has described it nicely in this posting:
    https://community.rapidminer.com/discussion/50538/how-to-use-macros

    And congratulations, you are now in the higher echelons of macro handling  ;)

    Best,
    David

  • lionelderkrikor
    lionelderkrikor New Altair Community Member
    Answer ✓
    Hi @1705410G,

    Can you try to define attribute name as %{loop_attribute} (or something like %{loop_attribute}_bis if you don't want that your initial attributes are removed) instead of #{loop_attribute} :  



    Hope it helps,

    Regards,

    Lionel

Answers

  • David_A
    David_A New Altair Community Member
    Answer ✓
    Hi,

    the problem here is how macros are parsed.
    In your case, first %{loop_attribute} is replaced with the attribute name, this is "2_speed". Then the eval() function tries to make sense of that string as a number or mathematical expression, what fails.

    In that case you need to use the seldom used #{loot_attribute} syntax. This returns the value corresponding to that attribute name.

    @mschmitz has described it nicely in this posting:
    https://community.rapidminer.com/discussion/50538/how-to-use-macros

    And congratulations, you are now in the higher echelons of macro handling  ;)

    Best,
    David

  • 1705410G
    1705410G New Altair Community Member
    edited January 2019
    HI David_A 

    #{loop_attribute} syntax worked!! Thank you!! But the results seems wrong

    As mentioned above, i'm using 2 separate Loop Attributes operator.

    Attribute filter type is set to subset with about 40 different attributes selected in each Loop Attributes operator. 
     

    However, there's only 1 column of results produced by the first loop and s
    econd loop (Shown below). Does it means that both Loop Attributes only loop once?  
      


    My question is how can I allow the 2 different loops to loop for all selected attributes?
    So I should be able to get 80 new columns in total. 40 for the first loop function and 40 for the second loop function.  

    P.S. How do I get the loop attributes to use back the same name rather than #{loop_attribute} since I have 40 over attributes in each Loop Attribute operator?


    Thank you!! 

    Regards,
    AY
  • lionelderkrikor
    lionelderkrikor New Altair Community Member
    Answer ✓
    Hi @1705410G,

    Can you try to define attribute name as %{loop_attribute} (or something like %{loop_attribute}_bis if you don't want that your initial attributes are removed) instead of #{loop_attribute} :  



    Hope it helps,

    Regards,

    Lionel
  • 1705410G
    1705410G New Altair Community Member
    Hi 

    It worked! Thank you so much to all that contributed!


  • kypexin
    kypexin New Altair Community Member
    In that case you need to use the seldom used #{loot_attribute} syntax. This returns the value corresponding to that attribute name.

    @David_A -- thanks for that secret knowledge, it took me an hour of my life to struggle with Loop Attributes before I have found this solution on the forum!

    PS one more proof how really useful and helpful RM community can be! MAGIC!
  • MartinLiebig
    MartinLiebig
    Altair Employee

    i am quite close to write a getValueOf(String attribute) function and add it to the expression parser. I got the feeling that this would fix this hazzle.

    BR,
    Martin
  • kypexin
    kypexin New Altair Community Member
    @mschmitz -- would be great!

    '#{macro}' notation is basically okay (if you know about it of course :) ), but having getValueOf(String attribute) would simplify the process structure in some cases. 

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.