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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
Anonymous
Not applicable

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.