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

"Saving Plots in R"

gbortz27gbortz27 Member Posts: 22 Contributor II
edited June 2019 in Help
I have been writing code in R but now whish to plot in R using the R extention node. say using ggplot2

I wanted to do this by plotting the output to a file. I tried setting the current directory using the R command setwd and the extention node does not allow this. I then tried to send the output to a file with no address ( png file ) , and would search for the file to see where it landed ..it does not seem to plot it out to a file. I then just plotted it , and it did nothing.

My aim is to send the R graph done under ggplot to a file in the Extention node  and then read the file to a report. is this possible ?

Does R plotting or Graphing work in the R extention node ..if so how ?

Thanks
Graham
Tagged:

Answers

  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458 Unicorn
    Hello

    It is possible to write plots to files. Here's an example (for Windows)
    <?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:execute_script_r" compatibility="5.3.000" expanded="true" height="76" name="Execute Script (R)" width="90" x="447" y="345">
            <parameter key="script" value="setwd(&quot;c:\\temp&quot;)&#10;png(file=&quot;plot.png&quot;)&#10;plot(iris)&#10;dev.off()"/>
            <enumeration key="inputs"/>
            <list key="results"/>
          </operator>
          <connect from_op="Execute Script (R)" 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>
    regards

    Andrew
  • farmerfarmer Member Posts: 15 Contributor II
    Hi,

    I posted this on the Problems and Support board: " I'm looking to capture the output from the R script somewhere in RapidMiner. If anyone uses R perhaps they could let me know how. Thanks" The Log view does not show, for example, the R regression output or summary results. Is there a way forward with this? Apologies for asking the same question on this board.
  • farmerfarmer Member Posts: 15 Contributor II
    Problem now solved. Some careless script coding on my part and now using the print() function, not Print(), to direct output to the console.

    As an aside: 1) is it possible to obtain the Log output without dates and times and 2) increase the size of the font? Thanks.
  • gbortz27gbortz27 Member Posts: 22 Contributor II
    Hi Andrew

    I managed to solve the printout to a file by reading your code and inserting the r part into a r execution code block.

    The html code you sent me did not execute..it brought up a normal execution block and not the R execute script block , sending me back a message that the R extention is not loaded ..( It definitely is loaded and working . !) ..wonder what the problem is..

    What I would ideally like to do is to send the graph file (.png) ( or object ) to the report generator which is now working for tables.

    There may be one of two ways which I cant get to work

    1) In the R code block , how would I send the graph file ( .png) to a Report Generator or Report block as an object ? Can I do it via the return ( list (...) ) statement at the end of the r function in the R execute and what do I put in the list ie the file name or a variable name of the graph)  If this can be done how do I read it into the Repport block..what are the configiuration parametres ( ie it cant be Data Table , I tried document or file (Error , the document has no pages ) .

    2) Reading the file from the directory ..How do i read this in ( Using Open File or what ?) , and then when it goes into the Report block , what are the right parametre settings , as asked above ?

    Thanks, this would really help.
    Graham
  • awchisholmawchisholm RapidMiner Certified Expert, Member Posts: 458 Unicorn
    Hello Graham

    I also have R extension/R script issues. Fortunately, I don't need to solve them just yet.

    As far as I know, there is no published interface to pass things to the various Report operators. To read files you can use `Read File`; from there my thought is to create an example set containing an HTML href link to the file and then using that in a table to point to the location.

    I haven't tried this

    regards

    Andrew
  • farmerfarmer Member Posts: 15 Contributor II
    Is one of the issues writing files? For example,.the write.csv((data frame name, file="file_nane') instruction does not seem to work. I need to insert a RapidMiner write icon in order to achive this.
  • David_ADavid_A Administrator, Moderator, Employee-RapidMiner, RMResearcher, Member Posts: 297 RM Research
    When writing files with an R script it is important to select the correct file paths to store your files.
    If you just use [tt]write.csv((data frame name, file="file_name.csv')[/tt]  R will store the file in the current working directory, which is a tmp folder.
    To store and retrieve your files, you have to declare a location in the file argument of the write function in R like [tt]write.csv((data frame name, file="C:\User\file_name.csv')[/tt]

    Regards,
    David
  • farmerfarmer Member Posts: 15 Contributor II
    Many thanks for that, appreciated. I thought that I had set the working directory with the setwd() command, but that did not do it. As you say, specifying the path name in file argument outputs the csv file correctly. On small point, one needs to reverse '\' to '/' as that is what R recognises in the path name.

    Best,

    farmer
  • farmerfarmer Member Posts: 15 Contributor II
    A new issue is that when I read a csv file and use the command print(file name), the log entry starts with the third observation, omitting the first two.
Sign In or Register to comment.