Forum Discussion

SPaine86's avatar
SPaine86
Helper I
5 years ago
Solved

R script "Token Comma expected"

Hi there,

 

Hoping for a second pair of eyes...

 

I'm trying to use a R Script to dump a Query into a csv file stored in SharePoint. I've followed this wonderful tutorial to set it all up using R, RStudio and Strawberry Perl. I'm getting a syntax error telling me a Token Comma is expected - but it looks OK to me. Can one of you be my second pair of eyes?

 

The formula reads:

= R.Execute("# 'dataset' holds the input data for this script#(lf)require(gdata)#(lf)write.table(trim(dataset), file="https://site.sharepoint.com/site/AnalysisTeam/Automated  Reporting/VA data.csv", sep = “,”, row.names = FALSE)#(lf)plot(dataset);",[dataset=#"Removed Columns"])

 

(I have added italics where Power BI says the token comma is missing)

 

I have no previous experience with R

 

Thank you in anticipation!

11 Replies

  • Hi SPaine86 

    The URL needs two sets of double quotes to escape it within the string it is inside i.e. ""url""

    Try this

     

    R.Execute("# 'dataset' holds the input data for this script#(lf)require(gdata)#(lf)write.table(trim(dataset), file=""https://site.sharepoint.com/site/AnalysisTeam/Automated  Reporting/VA data.csv"", sep = ",", row.names=FALSE)#(lf)plot(dataset);",[dataset=#"Removed Columns"])

     

    regards

    Phil

  • Hi SPaine86 ,

    I think the problem is in the following line. Not sure why there is a SEMI COLON after plot(dataset):

    plot(dataset);",[dataset=#"Removed Columns"])

     

    Thanks,

    Pragati

    • SPaine86's avatar
      SPaine86
      Helper I

      Thanks for your reply Pragati.

       

      The error seems to be with my URL/path. From after file=" the formula turns one colour. This is also where Power BI indicates that the comma should be. I have tried different paths including pointing to my own desktop, and these all have the same 'token comma' error.

       

      It may also be that the semi-colon also shouldn't be there, but the formula fails before it reaches that part - so I guess I'll find out once the path error is fixed!

  • SPaine86 , 

     

    Looks like link is not correct. I can see there is space on your link. If I am not wrong there won't be any spaces on a link. 

     

    Regards, 

    Manikumar

    • SPaine86's avatar
      SPaine86
      Helper I

      Hi Manikumar,

       

      Thank you for your reply. I have tried different links (including some without spaces and some which point to a local drive rather than SharePoint) and I am still getting a syntax error - so I don't think that is it unfortunately. Power BI is expecting a comma immediately after the " in file..

       

      Thanks

       

      Steve

      • Pragati11's avatar
        Pragati11
        Super User

        Hi SPaine86 ,

         

        Try on thing. In the following file path there is folder name with SPACES:

        https://site.sharepoint.com/site/AnalysisTeam/Automated  Reporting/VA data.csv"

         

        Can you try renaming your folder to something like "Automated_Reporting". This should be easy to achieve. Also your csv file name has got space in it as well. Try modifying it's name to "VA_data.csv"

         

        I think this will resolve the issue.

         

        Thanks,

        Pragati