Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Help needed - Use a file (custom type for R packag) stored on sharepoint as data source for R script

Hi 

 

I need some help accessing a file from a sharepoint location and using it as a source/data in an R script.

 

While this is an R issue, it also relates to the workflow of importing from a file from sharepoint in power bi desktop. So I'll cross post in the both the R and desktop forum.

 

I want to use a file stored in sharepoint as the source for an R script.

The file is a specific format which is used by a set of R packages.

 

I have a  taxonomy.rdf file stored on sharepoint.

I can access the file via the sharepoint connector

e.g. 

 

let
    Source = SharePoint.Files("https://mysite.sharepoint.com/sites/MST_EPA_IntelligenceandAnalysisTeamSite", [ApiVersion = 15]),
    #"taxonomy.rdf_https://mysite.sharepoint.com/sites/MST_EPA_IntelligenceandAnalysisTeamSite/Shared Documents/" = Source{[Name="epa_taxonomy_EDG_working.rdf",#"Folder Path"="https://mysite.sharepoint.com/sites/MST_EPA_IntelligenceandAnalysisTeamSite/Shared Documents/"]},
    Content = #"taxonomy.rdf_https://mysite.sharepoint.com/sites/MST_EPA_IntelligenceandAnalysisTeamSite/Shared Documents/"[Content]
in
    Content

But how do I pass that file/query/source as a file object to an R script ?

 

The R script runs on the file, so I don't want to parse it.

 

I have a an R script which if I am using that file locally is ( see blue text for use of file path)

 

setwd("Y:/Data//2019/test")
require(magrittr)
require(rdflib)
library(magrittr)
library(rdflib)
sparql <-
    'PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?a ?p
WHERE { ?a a ?p . 
        }'
out = "Y:/Data//2019/test/taxonomy.rdf" %>%
rdf_parse() %>%
rdf_query(sparql)
write.csv(out, file="testpbRDF6.csv")

My R skills are pretty rough so I don't know if you can pass the a query to the R script ?

 

I've tried a few combinations of embedding the sharepoint path into the R script without success.

 

If anyone has a simpler example query and can share your're a legend !

 

cheers

 

Simon

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Anonymous ,

You can try to use R.exclude function to execute r script string or r script who stored in local file.

Using R in Query Editor

Running Local R Scripts in Power BI

If you publish pbix file to power bi service, some of script operations will been blocked due to security reasons.(e.g. access external data source, import/export from specific path...)

Creating R visuals in the Power BI service#r scripts security

BTW, power bi service not support custom r packages. You can refer to following link to know supported packages:
R packages in the Power BI service

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Anonymous ,

You can try to use R.exclude function to execute r script string or r script who stored in local file.

Using R in Query Editor

Running Local R Scripts in Power BI

If you publish pbix file to power bi service, some of script operations will been blocked due to security reasons.(e.g. access external data source, import/export from specific path...)

Creating R visuals in the Power BI service#r scripts security

BTW, power bi service not support custom r packages. You can refer to following link to know supported packages:
R packages in the Power BI service

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.