Bug in

Rapidminerpartner
Rapidminerpartner New Altair Community Member
edited November 2024 in Community Q&A

Hello, everyone


I found a bug in "Execute R" operator

I am using R-3.6.0


Briefly, "Execute R" cannot compute mean function of R

I did

data[1,1] <- mean(data[3:5,4])

but it didn't work and why it didn't is written in the log file I attached


I believe it will not be able to compute var function either.


I attached the process and log files.

Please fix this problem for me


Thank you and have a nice day.


Best,

Best Answer

  • YYH
    YYH
    Altair Employee
    Answer ✓
    Hi @Rapidminerpartner

    It seems that R's mean does not behave well with dataframes. One workaround is to convert the data to a regular matrix before taking the mean:

    data[1,1] <- mean(data.matrix(data[3:5,4]))
    https://stackoverflow.com/questions/35485536/r-argument-is-not-numeric-or-logical-returning-na/52153758
    <?xml version="1.0" encoding="UTF-8"?><process version="9.4.000-BETA">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.4.000-BETA" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" breakpoints="after" class="retrieve" compatibility="9.4.000-BETA" expanded="true" height="68" name="Retrieve Iris" width="90" x="112" y="34">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="r_scripting:execute_r" compatibility="9.1.000" expanded="true" height="103" name="Execute R" width="90" x="313" y="34">
            <parameter key="script" value="# rm_main is a mandatory function, &#10;# the number of arguments has to be the number of input ports (can be none)&#10;rm_main = function(data)&#10;{&#10;    print('Hello, world!')&#10;    # output can be found in Log View&#10;    &#10;&#10;    data[1,1] &lt;- mean(data.matrix(data[3:5,4]))&#10;    &#10;    &#10;    # your code goes here&#10;&#10;    # for example:&#10;    data2 &lt;- as.data.table(matrix(1:16,4,4))&#10; &#10;    # connect 2 output ports to see the results&#10;    return(list(data,data2))&#10;}&#10;"/>
          </operator>
          <connect from_op="Retrieve Iris" from_port="output" to_op="Execute R" to_port="input 1"/>
          <connect from_op="Execute R" from_port="output 1" to_port="result 1"/>
          <connect from_op="Execute R" from_port="output 2" to_port="result 2"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    


Answers

  • YYH
    YYH
    Altair Employee
    Answer ✓
    Hi @Rapidminerpartner

    It seems that R's mean does not behave well with dataframes. One workaround is to convert the data to a regular matrix before taking the mean:

    data[1,1] <- mean(data.matrix(data[3:5,4]))
    https://stackoverflow.com/questions/35485536/r-argument-is-not-numeric-or-logical-returning-na/52153758
    <?xml version="1.0" encoding="UTF-8"?><process version="9.4.000-BETA">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.4.000-BETA" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" breakpoints="after" class="retrieve" compatibility="9.4.000-BETA" expanded="true" height="68" name="Retrieve Iris" width="90" x="112" y="34">
            <parameter key="repository_entry" value="//Samples/data/Iris"/>
          </operator>
          <operator activated="true" class="r_scripting:execute_r" compatibility="9.1.000" expanded="true" height="103" name="Execute R" width="90" x="313" y="34">
            <parameter key="script" value="# rm_main is a mandatory function, &#10;# the number of arguments has to be the number of input ports (can be none)&#10;rm_main = function(data)&#10;{&#10;    print('Hello, world!')&#10;    # output can be found in Log View&#10;    &#10;&#10;    data[1,1] &lt;- mean(data.matrix(data[3:5,4]))&#10;    &#10;    &#10;    # your code goes here&#10;&#10;    # for example:&#10;    data2 &lt;- as.data.table(matrix(1:16,4,4))&#10; &#10;    # connect 2 output ports to see the results&#10;    return(list(data,data2))&#10;}&#10;"/>
          </operator>
          <connect from_op="Retrieve Iris" from_port="output" to_op="Execute R" to_port="input 1"/>
          <connect from_op="Execute R" from_port="output 1" to_port="result 1"/>
          <connect from_op="Execute R" from_port="output 2" to_port="result 2"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
          <portSpacing port="sink_result 3" spacing="0"/>
        </process>
      </operator>
    </process>
    


  • Rapidminerpartner
    Rapidminerpartner New Altair Community Member

    Hello, yyhuang

    Thank you for your help

    It works now

    Have a nice day!