ANNOUNCEMENT: RAPIDMINER 9.1 BETA HAS BEEN RELEASED TODAY!   PLEASE DOWNLOAD AND GIVE FEEDBACK. ENJOY AND HAPPY RAPIDMINING!   -- @sgenzer – Community Manager

Problem with running R code in the application

jozeftomas_2020jozeftomas_2020 Member Posts: 40
edited November 9 in Help

Hi everyone
I want to use the R script contained in the RapidMiner. I can run R codes
For example, draw up super words. Do kmeans or fuzzy clustering but not run
Can anyone help?

 For example, this code
install.packages ("ppclust")
library (ppclust)
library (factoextra)
library (cluster)
library (fclust)
date (iris)
x = iris [, - 5]
x
pairs (x, col = iris [, 5])
res.fcm <- fcm (x, centers = 3)
v0 <- matrix (nrow = 3, ncol = 4,
      c (5.0, 3.4, 1.4, 0.3,
        6.7, 3.0, 5.6, 2.1,
        5.8, 2.7, 4.3, 1.4),
        byrow = TRUE)
print (v0)
res.fcm <- fcm (x, centers = v0)
v0 <- inaparc :: kmpp (x, k = 3) $ v
print (v0)
res.fcm <- fcm (x, centers = v0)

u0 <- inaparc :: imemberand (nrow (x), k = 3) $ u
res.fcm <- fcm (x, centers = 3, memberships = u0)
res.fcm <- fcm (x, centers = 3, initial = "hartiganwong", initial = "imember")
res.fcm <- fcm (x, centers = 3, dmetric = "correlation")
res.fcm <- fcm (x, centers = 3, m = 4)
res.fcm <- fcm (x, centers = 3)
as.data.frame (res.fcm $ u)
res.fcm $ v0
res.fcm $ v
summary (res.fcm)
res.fcm $ comp.time

Does not run

r.JPG

 

Tagged:

Best Answer

  • Thomas_OttThomas_Ott Posts: 1,762   Unicorn
    Solution Accepted

    @jozeftomas_2020 Here you go. This is simplified using the Text Processing extension in RapidMiner. I just used a bit of R code to draw the word cloud.

    wordcloud.png

     

     

     

     

    <?xml version="1.0" encoding="UTF-8"?><process version="8.2.001">
    <context>
    <input/>
    <output/>
    <macros/>
    </context>
    <operator activated="true" class="process" compatibility="8.2.001" expanded="true" name="Process">
    <process expanded="true">
    <operator activated="true" class="social_media:search_twitter" compatibility="8.1.000" expanded="true" height="68" name="Search Twitter" width="90" x="45" y="34">
    <parameter key="connection" value="Twitter"/>
    <parameter key="query" value="rapidminer"/>
    </operator>
    <operator activated="true" class="select_attributes" compatibility="8.2.001" expanded="true" height="82" name="Select Attributes" width="90" x="179" y="34">
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="Text"/>
    </operator>
    <operator activated="true" class="nominal_to_text" compatibility="8.2.001" expanded="true" height="82" name="Nominal to Text" width="90" x="313" y="34">
    <parameter key="attribute_filter_type" value="single"/>
    <parameter key="attribute" value="Text"/>
    </operator>
    <operator activated="true" class="text:process_document_from_data" compatibility="8.1.000" expanded="true" height="82" name="Process Documents from Data" width="90" x="447" y="34">
    <parameter key="prune_method" value="percentual"/>
    <list key="specify_weights"/>
    <process expanded="true">
    <operator activated="true" class="text:tokenize" compatibility="8.1.000" expanded="true" height="68" name="Tokenize" width="90" x="112" y="34"/>
    <connect from_port="document" to_op="Tokenize" to_port="document"/>
    <connect from_op="Tokenize" from_port="document" to_port="document 1"/>
    <portSpacing port="source_document" spacing="0"/>
    <portSpacing port="sink_document 1" spacing="0"/>
    <portSpacing port="sink_document 2" spacing="0"/>
    </process>
    </operator>
    <operator activated="true" class="text:wordlist_to_data" compatibility="8.1.000" expanded="true" height="82" name="WordList to Data" width="90" x="581" y="85"/>
    <operator activated="true" class="select_attributes" compatibility="8.2.001" expanded="true" height="82" name="Select Attributes (2)" width="90" x="715" y="85">
    <parameter key="attribute_filter_type" value="subset"/>
    <parameter key="attributes" value="word|total"/>
    </operator>
    <operator activated="true" class="r_scripting:execute_r" compatibility="8.1.000" expanded="true" height="82" name="Execute R" width="90" x="849" y="85">
    <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;&#9;library(&quot;wordcloud&quot;)&#10;&#9;library(&quot;RColorBrewer&quot;)&#10;&#9;&#10;&#9;png(&quot;C:\\Users\\TomOtt\\Desktop\\wordcloud.png&quot;, width=1280,height=800)&#10;&#9;wordcloud(words = data$word, freq = data$total, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8, &quot;Dark2&quot;))&#10;&#9;dev.off()&#10;&#9;&#10;&#9;return (data)&#10;}&#10;"/>
    </operator>
    <connect from_op="Search Twitter" from_port="output" to_op="Select Attributes" to_port="example set input"/>
    <connect from_op="Select Attributes" from_port="example set output" to_op="Nominal to Text" to_port="example set input"/>
    <connect from_op="Nominal to Text" from_port="example set output" to_op="Process Documents from Data" to_port="example set"/>
    <connect from_op="Process Documents from Data" from_port="word list" to_op="WordList to Data" to_port="word list"/>
    <connect from_op="WordList to Data" from_port="example set" to_op="Select Attributes (2)" to_port="example set input"/>
    <connect from_op="Select Attributes (2)" from_port="example set output" to_op="Execute R" to_port="input 1"/>
    <connect from_op="Execute 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>

Answers

  • rfuentealbarfuentealba Moderator, RapidMiner Certified Analyst, Member Posts: 196   Unicorn

    Hi @jozeftomas_2020

     

    You are not specifying the CRAN mirror to be used to download and install your package. A quick and dirty workaround would be to change your first line (this one):

     

    install.packages ("ppclust")

     

    Change that to:

     

    install.packages ("ppclust", repos = "http://cran.us.r-project.org")

     

    Or better:

     

    if (!require(ppclust)) install.packages ("ppclust", repos = "http://cran.us.r-project.org")

     

    Or even better, don't invoke package installations from your RapidMiner extension, do it from R directly, and/or configure your .Rprofile file.

     

    Hope it works for you.

     

    All the best,

     

     

    sgenzer
  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hello
    Thank you
    I did it, but it's an error again.
    I am a beginner and I do not know how to solve the problem.
    Sorry maybe you help again?
    r1.JPG
    And he also made a mistake in drawing up the wordcluod

    (In a suicide, I need a lot of wordcluod):smileysad:
    Do you have a sample code to run a clustering in the Rhapsody with the R code?
    Thanks if you send

  • rfuentealbarfuentealba Moderator, RapidMiner Certified Analyst, Member Posts: 196   Unicorn

    I'm a beginner in R, so I can't help you much. However, if you do the same you did in the first place for installing ppclust, it will work:

     

    install.packages ("factoextra", repos = "http://cran.us.r-project.org")

     

    Let's see how it goes this time.

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Thanks a lot


    Now this errorr3.JPG

  • rfuentealbarfuentealba Moderator, RapidMiner Certified Analyst, Member Posts: 196   Unicorn

    "there is no package fclust".

     

    Install the package.

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    I wrote this
    install.packages ("factoextra", repos = "http://cran.us.r-project.org")
    Open the same error

  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 816   Unicorn

    You should try testing your R code inside R first.  If you get errors there, then you definitely won't get it to run inside RapidMiner.

    In all the errors you have shown above, you appear to be referencing packages that don't exist---have you checked those package names carefully?

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hello
    Thankful
    The r code runs correctly. But there is an error in the rapidshare
    Could you check in Rapidminer?
    Thanks a lot

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40
    My code runs correctly on R, but not here.
    Can anyone help me?
  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn

    @jozeftomas_2020 your going to have to check if RapidMiner can access those packages. 

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hello
    How and by what steps can I do?
    May you tell me?
    Thankful

     

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn

    @jozeftomas_2020 R loads it's packages into folders on your computer. You should check if it's loading them into your user account where RM Studio can access. Then I would just take one Execute R operator and the type in "require(some library)" and run the process. If it doesn't break or complain, then RM Studio can access the library. Repeat till all  your libraries are able to load. If one fails, then you'll need to open up the R console and install it in the right directory where RM can find it. 

    sgenzer
  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hi Dear Professor @Thomas_Ott
    In this case, I Novice and beginner.
    Can you tell me what steps to take?
    Sorry to ask
    With respect

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn

    @jozeftomas_2020 in your R console, type the following:

    <SPAN class="pln">.libPaths</SPAN><SPAN class="pun">()</SPAN>

     That will tell you where the packages are being stored. Check that directory (or directories) to make sure the libraries are installed there. Then check where RapidMIner is calling the Rscript.exe from (see your RM Studio preferences). It could be that Rscript.exe is calling from a different R library. 

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

     

    Hello
    Thank you very much for your help.
    I gave this path

     

    C:/Program Files/R/R-3.4.3/bin/Rscript.exe


    I put this code in the script to draw the word cloud, but it did not work
    If my RAM is high. And how many times I tried. But this error every time.
    How to tell the code in the script on my data and on the third column of that text?

    r1.JPGr2.JPG


    Can I help me again?
    Thank you
    With respect

     

     

    library("tm")
    library("SnowballC")
    library("wordcloud")
    library("RColorBrewer")

    # Read the text file from internet
    filePath <- "C:/pfull_1.csv"
    text <- readLines(filePath)
    docs <- Corpus(VectorSource(text))
    inspect(docs)
    toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
    docs <- tm_map(docs, toSpace, "/")
    docs <- tm_map(docs, toSpace, "@)
    docs <- tm_map(docs, toSpace, "\\|")
    # Convert the text to lower case
    docs <- tm_map(docs, content_transformer(tolower))
    # Remove numbers
    docs <- tm_map(docs, removeNumbers)
    # Remove english common stopwords
    docs <- tm_map(docs, removeWords, stopwords("english"))
    # Remove your own stop word
    # specify your stopwords as a character vector
    docs <- tm_map(docs, removeWords, c("blabla1", "blabla2"))
    # Remove punctuations
    docs <- tm_map(docs, removePunctuation)
    # Eliminate extra white spaces
    docs <- tm_map(docs, stripWhitespace)
    # Text stemming
    # docs <- tm_map(docs, stemDocument)
    dtm <- TermDocumentMatrix(docs)
    m <- as.matrix(dtm)
    v <- sort(rowSums(m),decreasing=TRUE)
    d <- data.frame(word = names(v),freq=v)
    head(d, 10)
    set.seed(1234)
    wordcloud(words = d$word, freq = d$freq, min.freq = 1,
    max.words=200, random.order=FALSE, rot.per=0.35,
    colors=brewer.pal(8, "Dark2"))

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn

    @jozeftomas_2020 i think you have to write out wordcloud image. right after 'set.seed(1234)' try adding

     

    png("wordcloud.png", width=1280,height=800)
    wordcloud(words = d$word, freq = d$freq, min.freq = 1,
    max.words=200, random.order=FALSE, rot.per=0.35,
    colors=brewer.pal(8, "Dark2"))
    dev.off()

     You might have to path wordcloud.png to some directory or it will save it to the default R directory somewhere.

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hello dear Professor @Thomas_Ott
    I wrote this

    png ("D: /wordcloud.png", width = 1280, height = 800)
    wordcloud (words = d $ word, freq = d $ freq, min.freq = 1,
      max.words = 200, random.order = FALSE, rot.per = 0.35,
      colors = brewer.pal (8, "dark2"))
    dev.off ()


    But again the same error went up.
    Please tell me what is the problem?
    Is it possible to send me the process that was implemented?
    Thank you very much for your help

     

    And I'm going to run the code on my data
    I loaded the data and then with the 'select attribute' operator I chose my text column and then I connected to the 'excute R' operator, but the same error occurred again.
    Could you guide how to provide data and text columns to run the code?
    Sorry sorry i'm asking

     


    With respect

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    hello

    sorry..

    please help me..

    :smileysad:

    No matter how hard I try. It's not good. And I am not able to draw the words of the cloud

  • jozeftomas_2020jozeftomas_2020 Member Posts: 40
     






    Hi @ Thomas_Ott, dear
    I really do not know how to thank you. Thank you:heart:
    Your code surprised me
    that was perfect
    Just excuse me
    I know there is a lot of demand. But I could not do it myself.
    Can I still get help with you?
    About that
    How can I do the clustering of the texts by R in the rapidminer program
     And what is the shape of the clusters with R?

    For example, I do not know how to use these codes
    http://www.sthda.com/english/wiki/print.php?id=237
    Use R to cluster texts in the RapidMiner.

    Could you help in this case?
    Excuse me and thank you very much
    We wish the best for you
    Yours sincerely
    With respect





  • jozeftomas_2020jozeftomas_2020 Member Posts: 40


    Hello
    Excuse me Mr. @Thomas_Ott
    I tried a lot to help with the RapidMiner and R to Hierarchical clustering on my data, but not
    Maybe according to this code
    https://rpubs.com/saqib/DocumentClustering
    help me?
    With respect
    Wish for you

    REgards

  • Thomas_OttThomas_Ott RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 1,762   Unicorn

    @jozeftomas_2020 do a search through the community for a sample of clustering with text data, there in there somewhere. I can't help you right now because I'm swamped with work. Maybe some other intrepid community member can help!

    sgenzer
  • jozeftomas_2020jozeftomas_2020 Member Posts: 40

    Hello
    Thomas_Ott
    So much thanks so much.:heart:
    Thank you
    I ask other friends if it is possible for you. Help me out here?
    How do you make steps like this?
    (stemming, tokenize, filter token by length, remove stop word),
    And then tf / idf and I can do hierarchical and clustering. Like RapidMiner 
      Do I do with R code? Of course, in the RapidMiner program.
    Just enter the data and bring the execute R operator. Do all the preprocessing steps and tf / idf and clustering by R?
    Thanks if you help
    Thanks

  • Telcontar120Telcontar120 Moderator, RapidMiner Certified Analyst, RapidMiner Certified Expert, Member Posts: 816   Unicorn

    There are operators for all of these standard text mining functions built directly into RapidMiner, which can be used inside the "Process Documents" operator.  That operator will also generate the TF-IDF word vector.  No need to use R for all that.  If you search the forum for text mining, you will find many existing threads with examples of these.  

    Brian T.
    Lindon Ventures 
    Data Science Consulting from Certified RapidMiner Experts
Sign In or Register to comment.