The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

how to create/edit macro in execute R?

jujujuju Member Posts: 39 Maven
edited November 2018 in Help

Hi I want to runing some sql query in RM, and need to use R to generate that sql code.

I'm thinking of sending the sql code to a macro and referring to the macro in "read database" process?

 

But how do I create/edit a macro in R? Any help's appreciated. Thank you!

Tagged:

Answers

  • jujujuju Member Posts: 39 Maven

    I figured out a way:

    generate something in R, and make it the output of R by returning data.frame(x = something)

     

    And send this output data frame into a 'extract macro' process, and extract column x, first row - the content is something.

     

    Code:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="6.4.000">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="6.4.000" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="r_scripting:execute_r" compatibility="6.4.000" expanded="true" height="76" name="Execute R" width="90" x="112" y="30">
    <parameter key="script" value="&#10;rm_main = function(){&#10;&#10;&#9;data.frame(x = 50)&#10;&#10;}&#10;"/>
    </operator>
    <operator activated="true" class="extract_macro" compatibility="6.4.000" expanded="true" height="60" name="Extract Macro" width="90" x="246" y="30">
    <parameter key="macro" value="nn"/>
    <parameter key="macro_type" value="data_value"/>
    <parameter key="attribute_name" value="x"/>
    <parameter key="example_index" value="1"/>
    <list key="additional_macros"/>
    </operator>
    <operator activated="true" class="r_scripting:execute_r" compatibility="6.4.000" expanded="true" height="76" name="Execute R (2)" width="90" x="447" y="30">
    <parameter key="script" value="rm_main = function(nn = %{nn}){&#10;&#10;&#9;&#10;&#9;print(nn*2)&#10;&#9;&#10;&#9;data.frame(new = nn*2)&#10;}&#10;"/>
    </operator>
    <connect from_op="Execute R" from_port="output 1" to_op="Extract Macro" to_port="example set"/>
    <connect from_op="Execute R (2)" from_port="output 1" to_port="result 1"/>
    <portSpacing port="source_input 1" spacing="0"/>
    <portSpacing port="sink_result 1" spacing="0"/>
    <portSpacing port="sink_result 2" spacing="0"/>
    </process>
    </operator>
    </process>
Sign In or Register to comment.