Forum Discussion
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 = "[email protected]", to = "[email protected]", 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.
I find the solution.
script_files <- list.files(path = folder_path, pattern = "\\.csv$", full.names = TRUE)
3 Replies
- Tinus1905Resolver I
I find the solution.
script_files <- list.files(path = folder_path, pattern = "\\.csv$", full.names = TRUE)
- AnonymousNot 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.
- Tinus1905Resolver I
Anonymous ; I read the article but I don't know how to use that in my R scripts.