Forum Discussion

useless's avatar
useless
New Member
4 years ago
Solved

R script

Please don't link to https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-r-in-query-editor

 

I am just trying to get output matching the input.

I am using a .csv as a source as that webpage is saying.

I then add an R script as that webpage is saying.

 

I just want the table to come out as a table.

Right now, I have a table as excepted prior this step, and then after this step,

I have a different table, where one column is the variable name, and the other is the table nested within.

 

I want the table to look as it did (so in future I can actually do something with it in the script)

 

The script is:

output <- data.frame(dataset)

and I've tried variants like: output <- dataset, etc etc

 

What am I doing wrong that I can't get passed even this trivial step?

I honestly can't believe that I even need to post on a forum to find answer for this

 

  • Try clicking on the resulting Table in the Value column.

     

    You could also select that cell at this step by appending "{0}[Value]".

    #"Run R script" = R.Execute("output <- dataset",[dataset=Source]){0}[Value],

     

4 Replies

  • Please share your M code from the Advanced Editor so that we can replicate what you're seeing.

    • useless's avatar
      useless
      New Member

      Thanks for responding. I copied and pasted it below. I had to remove some stuff like file path and some column names etc just for privacy. I added screenshot of before / after the step.

       

       

      let
          Source = Csv.Document(File.Contents("C:\Users\____\Documents\____\___Table.csv"),[Delimiter=",", Columns=34, Encoding=1252, QuoteStyle=QuoteStyle.None]),
          #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
          #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"", Int64.Type}, {"id", Int64.Type}, {"date", type date}, {"time", type text}, {"outcome_1", type text}, {"outcome_2", type text}, {"duration", type text}, {"file_name", type text}}),
          #"Run R script" = R.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)output <- dataset",[dataset=Source]),
          #"Removed Columns" = Table.RemoveColumns(#"Run R script",{""}),
          #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"id", type text}})
      in
          #"Changed Type1"

       

       

       

       

      For context, my actual goal in the R script was to read a different .csv, run some logic, add some columns to the current table, then have it propagate into Power BI for visualisation, whilst also saving a truncated version to a third .csv.

      I get how to do it in R, I just don't understand why the data is getting nested into a field before I do anything to it.

       

      • AlexisOlson's avatar
        AlexisOlson
        Super User

        Try clicking on the resulting Table in the Value column.

         

        You could also select that cell at this step by appending "{0}[Value]".

        #"Run R script" = R.Execute("output <- dataset",[dataset=Source]){0}[Value],