Execute R: Date Missing in Output

Oprick
Oprick New Altair Community Member
edited November 5 in Community Q&A
Hi,
In my process  I have have two operators. the first is read.excel and the other is Execute R. In the latter a script fills NAs in time series (daily). All good with that and when I test the script in Rstudio everything seems  to be in place. Though all dates in the output of the operator are missing "?".

Well... in past similar situations that I came across already, after reading some posts here, I was able to proceed by transforming date to character and then in R I would use nominal to date. Which is the solution given in this old thread:  https://community.rapidminer.com/discussion/41481/why-date-data-is-missing-after-output-from-execute-r.

If the script works in Rstudio  I guess that the issue is just "coming back"  to Rapidminer, but what I don't get is why transforming date to character in R is not a solution.

Your help is much appreciated because this is nerve-racking :smile:

RM process file and data source example enclosed.

Thanks,
Pedro

Best Answer

  • hughesfleming68
    hughesfleming68 New Altair Community Member
    edited February 2019 Answer ✓
    This is a Posix date problem.   dateoutput<-as.POSIXct(date, tz = "")

    In your code:-

    ds2<-ds2%>%
      fill(grw,block)

    ds2$day<-as.POSIXct(ds2$day)

    return(as.data.frame(ds2))

    or just import the process I uploaded.

    regards,

    Alex

Answers

  • SGolbert
    SGolbert New Altair Community Member
    Hi Pedro,

    let me see if I understood correctly. The problem is that in the output of the Execute R operator, the dates columns are missing?

    If you are already transforming to character in R, my guess is that the input dates are not being passed correctly to R. My suggestion is to read the excel files directly in R, RapidMiner can pass the file name if necessary.

    Another option is to do the time series processing in RapidMiner, which can be a time saver in the long run.

    Regards,
    Sebastian

  • hughesfleming68
    hughesfleming68 New Altair Community Member
    edited February 2019
    Try putting in a date to nominal operator with the date format yyyy-MM-dd and see if that works. If that still fails then you need to look at how to work with Posix dates in R to being them back into Rapidminer. POSIXct is where you would need to start.

    regards,

    Alex
  • Oprick
    Oprick New Altair Community Member
    Hi,
    @SGolbert exactly.

    What is really confusing me is that in Rstudio, after running the script I get a data frame (pic enclosed). I guess that the problem doesn't have to do with importing to R.



    I have already tried put date format as yyyy-mm-dd in Rapidminer,but in the end when output of  Execute R is always a date column filled with "?".

    @hughesfleming68:Already try to transform  before in nominal.

    Still getting the "?" dates

    Regards,
    Pedro
  • hughesfleming68
    hughesfleming68 New Altair Community Member
    edited February 2019 Answer ✓
    This is a Posix date problem.   dateoutput<-as.POSIXct(date, tz = "")

    In your code:-

    ds2<-ds2%>%
      fill(grw,block)

    ds2$day<-as.POSIXct(ds2$day)

    return(as.data.frame(ds2))

    or just import the process I uploaded.

    regards,

    Alex

  • Oprick
    Oprick New Altair Community Member
    @hughesfleming68 thanks a  lot. That works. 
    In the meanwhile I was able to find a workaround: I just transformed, in R, date column to character and add a random piece of string with "//" as separator. Then, "back" in RM, I used "split" and "nominal  to date". This allowed me to proceed work.

    But of course... Your solution is way more elegant and I'll stick to it.

    Again thanks a lot.

    Regards,
    Pedro