none
Error: Mapped variable must be of class type data.frame at this time. RRS feed

  • Question

  • Hello Jaya,

    Very simple problem I am having, multiple keywords extraction from my texts. Giving you two samples, both are working perfectly in RStudio, but Azure Studio is giving error (Error: Mapped variable must be of class type data.frame at this time). Little help please. 

    sample1:

    df <- main.df$Comment

    keywords<-c("yhteens d eli|questions|ok m bit jealous|possible|onko|samaa")
    matches <- unique(grep(paste(keywords, collapse = "|"), main.df$Comment, value = TRUE))
    print(matches)

    sample2:

    include <- function (theList, toMatch){
            matches <- unique (grep(paste(toMatch,collapse="|"), 
                                    theList, value=TRUE))
            return(matches)
    }

    SentencesWithKeywords <- include(main.df$Comment, keywords)

    BR,

    Bipul

    Wednesday, January 27, 2016 10:21 PM

Answers

  • Hi Bipul,

    This seems to work:

    Sample input data:

    Sample output:

    Code within Execute R Script module:

    # Map 1-based optional input ports to variables
    dataset1 <- maml.mapInputPort(1) # class: data.frame
    df <- dataset1$comment
    
    keywords<-c("yhteens d eli|questions|ok m bit jealous|possible|courier")
    matches <- unique(grep(paste(keywords, collapse = "|"), dataset1$comment, value = TRUE))
    print(matches) 
    include <- function (theList, toMatch){
         matches <- unique (grep(paste(toMatch,collapse="|"), 
                                 theList, value=TRUE))
         return(matches)}
     
    SentencesWithKeywords <- include(dataset1$comment, keywords) 
     
    data.set <- as.data.frame(SentencesWithKeywords)
    # Select data.frame to be sent to the output Dataset port
    maml.mapOutputPort("data.set");
    
    
    

    Is this what you are trying to do?

    Regards,
    Jaya.

    • Marked as answer by Bipul Mohanto Friday, January 29, 2016 9:32 PM
    Thursday, January 28, 2016 10:59 PM

All replies

  • Hi Bipul,

    I suspect this has to do with the class of the input/output from the 'Execute R Script' module.

    Could you ensure that your input goes into port-1:

    dataset1 <- maml.mapInputPort(1) # class: data.frame

    and output is mapped to data.set which is also a data frame:

    maml.mapOutputPort("data.set");

    Hope this helps fix the issue.

    Regards,
    Jaya.


    Wednesday, January 27, 2016 10:39 PM
  • Hi again Jaya,

    Definitely the port I connected is right, I used the port1 only. Look bellow here, I really cannot find any proper explanation of this problem. 

    Wednesday, January 27, 2016 11:17 PM
  • Hi Bipul,

    Could you also check to see if the output data.set is also of type data.frame? I am not sure if you are trying to output something via your 'Execute R Script' module.

    maml.mapOutputPort("data.set");

    Just did a quick test with your sample code-1: it seems to work.

    Output:

    Thanks,
    Jaya.


    Thursday, January 28, 2016 3:15 PM
  • Hello Jaya, 

    For say, I have a 1000 rows of sentences. I am giving certain keywords 

    keywords<-c("yhteens d eli|questions|ok m bit jealous|possible|onko|samaa")

    and finally want to show the sentences those hold the certain keywords. I have used as.data.frame(matches)  as you have showed, but it is giving all the sentences together in one row, one column. Where I should get something like 12 rows, 1 column mentioned keywords. 

    I really do not understand what is the difference between AzureR and normal RStudio. When I work with RStudio everything works so smoothly but when I bring the same code to Azure ML, it really creates problem.

    Thursday, January 28, 2016 9:14 PM
  • Hi Bipul,

    Yes, there are some differences between RStudio and Azure ML's R. First, R in Azure ML runs in a sandbox environment and also the version might be different from what is needed for some packages. Also in Azure ML's 'Execute R Script' module, you need to bring in your data using the maml.mapInputPort(1) # class: data.frame

    and export using:

    maml.mapOutputPort("data.set");

    Other than that, ideally the code should run in Azure ML with minor edits.

    Now that we have confirmed that your sample code works for 1 sentence. Pls check to see if your 1000 lines of code are imported as a data frame into this 'Execute R Script' module accurately. Could you attach a screen shot of your input dataset?

    Regards,
    Jaya.   

    Thursday, January 28, 2016 9:38 PM
  • Look, here.....for simplification I am giving first 162 rows. The same code (sample1, sample2) is working fine in RStuio, just need to use cbind to rearrange the output match word in row wise. But it is not working at all. in Azure. :( can you propose any other method, I need to extract multiple keywords or sentences.

    Thursday, January 28, 2016 10:06 PM
  • Hi Bipul,

    This seems to work:

    Sample input data:

    Sample output:

    Code within Execute R Script module:

    # Map 1-based optional input ports to variables
    dataset1 <- maml.mapInputPort(1) # class: data.frame
    df <- dataset1$comment
    
    keywords<-c("yhteens d eli|questions|ok m bit jealous|possible|courier")
    matches <- unique(grep(paste(keywords, collapse = "|"), dataset1$comment, value = TRUE))
    print(matches) 
    include <- function (theList, toMatch){
         matches <- unique (grep(paste(toMatch,collapse="|"), 
                                 theList, value=TRUE))
         return(matches)}
     
    SentencesWithKeywords <- include(dataset1$comment, keywords) 
     
    data.set <- as.data.frame(SentencesWithKeywords)
    # Select data.frame to be sent to the output Dataset port
    maml.mapOutputPort("data.set");
    
    
    

    Is this what you are trying to do?

    Regards,
    Jaya.

    • Marked as answer by Bipul Mohanto Friday, January 29, 2016 9:32 PM
    Thursday, January 28, 2016 10:59 PM
  • Dear Ms. Jaya,

    Thank you so much, I am really happy and grateful for the help. You really saved me. :) It is working very fine, I will be more careful from next time to ignore these kind of problems.

    Have a good day.

    Warm Regards,

    Bipul Mohanto

    Saturday, January 30, 2016 11:49 AM
  • Hi Bipul,

    Good to hear your issue is resolved, thanks for the confirmation!

    Regards,
    Jaya.

    • Marked as answer by Bipul Mohanto Tuesday, February 2, 2016 12:23 AM
    • Unmarked as answer by Bipul Mohanto Tuesday, February 2, 2016 12:23 AM
    Monday, February 1, 2016 3:38 PM