<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Query Editor R Script Date Time Issues in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90593#M3217</link>
    <description>&lt;P&gt;RStudio integration does exist.&amp;nbsp; Can't remember which release but it's been around for at least a couple of months I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File -&amp;gt; Options and Settings -&amp;gt; Options -&amp;gt; R Scripting you can associate an external IDE with Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, from within the R Visual edit window there's a new icon on at the top, an arrow pointing North East - this will copy your code to your associated IDE and extremely conveniently package up the data items you pass into the R Visual and store them in a referenced CSV within R Studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any changes you make to the code you will have to manually cut and paste back to Power BI but it's still pretty nifty the way they have done the integration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Sacha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2016 22:21:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-11-16T22:21:12Z</dc:date>
    <item>
      <title>Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90540#M3215</link>
      <description>&lt;P&gt;So I'm trying to use the Run R Script in the Query Editor. I'd like to run statistical models using R, however, doing even the simpliest tasks seem a bit difficult.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that the 'dataset' provided automatically is a data.frame, but the columns that have a datetime are converted to factors &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; I was able to verify that doing the following:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;# 'dataset' holds the input data for this script
output &amp;lt;- dataset
output$discovery_date_utc_type &amp;lt;- class(output$discovery_date_utc)&lt;/PRE&gt;&lt;P&gt;The result is factor, so I did the following to get around that...&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;output &amp;lt;- as.data.frame(dataset, stringsAsFactors = FALSE)&lt;/PRE&gt;&lt;P&gt;Then I was able to manipulate the column back into a datetime column doing the following:&lt;/P&gt;&lt;PRE&gt;# I previously loaded the lubridate package as I was still having issues with standard R date time data types??? It would work in RStudio, but not in PowerBI :(
#library(lubridate)
output$discovery_date_utc_new &amp;lt;- ymd_hms(result$discovery_date_utc)&lt;/PRE&gt;&lt;P&gt;This worked!!!! Yeah &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; The output data frame has a new column and it is a date time column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now here is my issue...&amp;nbsp;&lt;BR /&gt;I then wanted to get the maximum date and put that into a variable end_date... but I'm getting an error.&lt;/P&gt;&lt;PRE&gt;end_date &amp;lt;- max(output$discovery_date_utc_new)&lt;/PRE&gt;&lt;P&gt;Resulting Error (this works fine in RStudio):&lt;/P&gt;&lt;PRE&gt;DataSource.Error: ADO.NET: R script error.
Warning message:
In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
  embedded nul(s) found in input
Loading required package: methods

Attaching package: 'lubridate'

The following object is masked from 'package:base':

    date

Error in lapply(list(...), .num_to_date) : object 'result' not found
Calls: ymd_hms -&amp;gt; .parse_xxx_hms -&amp;gt; unlist -&amp;gt; lapply
Execution halted

Details:
    DataSourceKind=R
    DataSourcePath=R
    Message=R script error.
Warning message:
In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
  embedded nul(s) found in input
Loading required package: methods

Attaching package: &amp;amp;#39;lubridate&amp;amp;#39;

The following object is masked from &amp;amp;#39;package:base&amp;amp;#39;:

    date

Error in lapply(list(...), .num_to_date) : object &amp;amp;#39;result&amp;amp;#39; not found
Calls: ymd_hms -&amp;amp;gt; .parse_xxx_hms -&amp;amp;gt; unlist -&amp;amp;gt; lapply
Execution halted

    ErrorCode=-2147467259
    ExceptionType=Microsoft.PowerBI.Radio.RScriptRuntimeException&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2016 20:07:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90540#M3215</guid>
      <dc:creator>jb1t</dc:creator>
      <dc:date>2016-11-16T20:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90570#M3216</link>
      <description>&lt;P&gt;Okay, so I got it to work... using lubridate and setting na.rm=TRUE when doing the max calculation. I'm going to have to verify, but my data shouldn't have any na's in the column???&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;# 'dataset' holds the input data for this script
library(lubridate)

output &amp;lt;- as.data.frame(dataset, stringsAsFactors = FALSE)
output$discovery_date_utc_new &amp;lt;- ymd_hms(output$discovery_date_utc)

end_date &amp;lt;- max(output$discovery_date_utc_new, na.rm=TRUE)
output$end_date &amp;lt;- end_date&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyhow, in my VERY limited time working with R and R within a Query Edit window in PowerBI... Here&amp;nbsp;are my wish list items:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Integration into RStudio IDE&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;If that isn't doable at least a way to see output, so I can print variables from the R script and review them&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Wed, 16 Nov 2016 21:02:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90570#M3216</guid>
      <dc:creator>jb1t</dc:creator>
      <dc:date>2016-11-16T21:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90593#M3217</link>
      <description>&lt;P&gt;RStudio integration does exist.&amp;nbsp; Can't remember which release but it's been around for at least a couple of months I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File -&amp;gt; Options and Settings -&amp;gt; Options -&amp;gt; R Scripting you can associate an external IDE with Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, from within the R Visual edit window there's a new icon on at the top, an arrow pointing North East - this will copy your code to your associated IDE and extremely conveniently package up the data items you pass into the R Visual and store them in a referenced CSV within R Studio.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any changes you make to the code you will have to manually cut and paste back to Power BI but it's still pretty nifty the way they have done the integration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;P&gt;Sacha&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 22:21:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90593#M3217</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-11-16T22:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90637#M3218</link>
      <description>&lt;P&gt;Thanks Sacha, however, I'm talking about integration within the Power BI Query Editor... not within R visuals.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 00:50:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90637#M3218</guid>
      <dc:creator>jb1t</dc:creator>
      <dc:date>2016-11-17T00:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90843#M3223</link>
      <description>Yup, you're correct. It quite clearly mentions query editor in the post title. Apologies.&lt;BR /&gt;&lt;BR /&gt;Hopefully they will introduce IDE support for R Scripting throughout Power BI soon.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Sacha</description>
      <pubDate>Thu, 17 Nov 2016 09:20:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/90843#M3223</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-11-17T09:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/92886#M3294</link>
      <description>&lt;P&gt;So I got the code working, but found two issues...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;One are that dates are being converted to character factors&lt;/LI&gt;&lt;LI&gt;Two it seems that passing data that has non-printable unicode characters from PowerBI to an R dataframe seems to have an issue. By clicking the clean text for every text column prior to executing an R script seemed to fix the issue.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:43:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/92886#M3294</guid>
      <dc:creator>jb1t</dc:creator>
      <dc:date>2016-11-22T19:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Query Editor R Script Date Time Issues</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/92888#M3295</link>
      <description>&lt;P&gt;So I got the code working, but found two issues...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;One are that dates are being converted to character factors&lt;/LI&gt;&lt;LI&gt;Two it seems that passing data that has non-printable unicode characters from PowerBI to an R dataframe seems to have an issue. By clicking the clean text for every text column prior to executing an R script seemed to fix the issue.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 22 Nov 2016 19:43:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Query-Editor-R-Script-Date-Time-Issues/m-p/92888#M3295</guid>
      <dc:creator>jb1t</dc:creator>
      <dc:date>2016-11-22T19:43:45Z</dc:date>
    </item>
  </channel>
</rss>

