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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Tinus1905
Resolver I
Resolver I

Export and email a table or report from PowerBi

I have a table in PowerBi with an R script for exporting on the local pc. Every week the table changed to the previous week. 

The R script exports a CSV on the local pc with the name of the week of the column in the table. 

Example: TEST 01-2024, TEST 02-2024 etc. 

 

# 'dataset' holds the input data for this script
week <- unique(dataset$Week) - 1
year <- format(Sys.time(), "%Y")
Table <- paste0("\\\\af01\\Users\\Tinus\\Desktop\\new\\TEST ", week, "-", year, ".csv")
write.table(dataset, file = Table, sep = ";", na = "", row.names = FALSE, quote = FALSE)

 

Email R script is no problem but how can I change the R script so that the attachment is the Export from the above R script. 

 

library(mailR)
send.mail(from = "user@sender.com",
          to = "user@recipient.com",
          subject = "Test email subject",
          body = "Test emails body",
          smtp = list(host.name = "smtp.mailtrap.io", port = 25,
                      user.name = "********",
                      passwd = "******", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

 

There are multible files in the folder so just add "attach.files" in the R script does not solve the problem. 

I also tried another solution, for example: Power Automate. But I cant found a solution that exports the file on the local pc. 

 

Many thanks. 

1 ACCEPTED SOLUTION
Tinus1905
Resolver I
Resolver I

I find the solution. 

 

script_files <- list.files(path = folder_path, pattern = "\\.csv$", full.names = TRUE)

View solution in original post

3 REPLIES 3
Tinus1905
Resolver I
Resolver I

I find the solution. 

 

script_files <- list.files(path = folder_path, pattern = "\\.csv$", full.names = TRUE)

Anonymous
Not applicable

Hi @Tinus1905 

You can refer to thef following link.

R: Source R files in an attached environment (r-project.org)

Sending Email Attachement Through Outlook in R with RDCOMClient - Stack Overflow

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous ; I read the article but I don't know how to use that in my R scripts. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.