I have done a series of blog posts on how R can be used in Power BI. I have also created quick videos for each of those posts and I will do the same for this post. I find it easier and more efficient to share this information via video than through a narrative with screenshots. In this blog post, I’m going to share the code that can be used to check if a file exist prior to processing of that file. I will record a video that goes in more depth and include that in the blog post later.
Check if file exist
As someone who comes from an enterprise BI background, I am always looking for ways to handle things I would have previously done with SSIS. With R integration we have a lot of new possibilities.
The Code:
fileexists <- FALSE
fileName <- “C:\\Backup\\Blogs\\R – Check if File Exist\\CustomerSales1.csv“
while (fileexists == FALSE)
{
#fileexists = TRUE ##Test Expression
fileexists <-
if(
file.exists(fileName))
{TRUE} else {FALSE}
print(fileexists)
## Add 3 second Delay
Sys.sleep(3)
}
data = read.csv(fileName)
head(data)